Can't find it quickly in the reference books.
Max allowed length for a javascript string?
Collapse
This topic is closed.
X
X
-
Douglas Crockford
Re: Max allowed length for a javascript string?
> Can't find it quickly in the reference books.
The ECMAScript Programming Language Specification does not specify a maximum
length. The maximum length with will be implementation-specific. For some
implementations , it will be a function of available memory, but you should not
rely on that if portability is important.
-
Richard Cornford
Re: Max allowed length for a javascript string?
"Douglas Crockford" <nospam@laserli nk.net> wrote in message
news:9a027$3fa7 c56d$44a4aebc$9 152@msgid.megan ewsservers.com. ..
<snip>[color=blue]
>... . The maximum length with will be implementation-specific. ...[/color]
In microsoft.publi c.scripting.jsc ript, Michael Harris
(Microsoft.MVP. Scripting), who might be expected to know, quoted:-
<quote Message-ID: <#CP34PocDHA.17 44@TK2MSFTNGP12 .phx.gbl>
In JScript, variant string variables have the same limit as in VBScript,
up to 2^31 characters.
String *literals* (as in "this is a literal") have (IIRC) a limit ~2^10
(1024) characters.
</quote>
- for the JScript implementation.
Richard.
Comment
-
Wade G. Pemberton
Re: Max allowed length for a javascript string?
Richard Cornford wrote:
I can tell from experience it's not 1024. The last string I used was over
23K bytes. However, I just wanted to make sure the limit wasn't something
like 2^16, which I'll collide with shortly. It's just a packing script
to export to MS Access from webdom. Since javascript has C as it's
progenitor, that's probably the limit. I've forgotten that limit, and
there's no book handy.
Wade
[color=blue]
> "Douglas Crockford" <nospam@laserli nk.net> wrote in message
> news:9a027$3fa7 c56d$44a4aebc$9 152@msgid.megan ewsservers.com. ..
> <snip>[color=green]
> >... . The maximum length with will be implementation-specific. ...[/color]
>
> In microsoft.publi c.scripting.jsc ript, Michael Harris
> (Microsoft.MVP. Scripting), who might be expected to know, quoted:-
>
> <quote Message-ID: <#CP34PocDHA.17 44@TK2MSFTNGP12 .phx.gbl>
> In JScript, variant string variables have the same limit as in VBScript,
> up to 2^31 characters.
>
> String *literals* (as in "this is a literal") have (IIRC) a limit ~2^10
> (1024) characters.
> </quote>
>
> - for the JScript implementation.
>
> Richard.[/color]
Comment
-
Lasse Reichstein Nielsen
Re: Max allowed length for a javascript string?
"Wade G. Pemberton" <w_pemberton@sp rynet.com> writes:
[color=blue]
> I can tell from experience it's not 1024. The last string I used was over
> 23K bytes.[/color]
It is highly browser dependent.
I just created a string literal in IE 6 that was 2^20 (~1M) characters
long. It took a while to parse! I also created a string that was 2^24
characters long. Then I wrote it as a string literal, and it hasn't
finished parsing it yet.
Mozilla breaks between 2^15 and 2^16 (32768 and 65536).
Opera 7.21 breaks somewhere between 2^11 and 2^12 (2048 and 8192).
[2^16?][color=blue]
> Since javascript has C as it's progenitor, that's probably the
> limit.[/color]
C is not Javascript's progenitor any more than Java is. All they share
is the syntax.
C has no inherent limits, although most implementations have a size_t
that is 32-bit.
/L 'please trim your quotes'
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Comment
-
Grant Wagner
Re: Max allowed length for a javascript string?
Why not just test it?
String.prototyp e.repeat = function(n) {
return new Array(n + 1).join(this);
}
var s = "x".repeat(Math .pow(2, 23)) + "y";
document.write( s.charAt(s.leng th - 1));
Anything larger in IE and I get an Out of memory error trying to *construct* the
string, but that's probably due to the implementation I'm using (constructing
the array and using .join()). I was able to get Firebird up to
..repeat(Math.p ow(2, 22)) before it completely gave up the ghost and stopped
responding. Interestingly enough, Opera 7.21 seemed particularly adept at this
task, and was able to construct a string 2^31 long almost instantly.
As for any limit in C having an effect on a limit in JavaScript, that's silly. A
String in JavaScript is an object containing a set of unicode characters, as
well as various properties and methods, isn't a string in C simply an area of
memory at begun at some location, and terminated by a \0? So why should there be
an artificial limit in C at all?
Considering the modern browsers I tested were capable of setting and retrieving
the last character of a string at least 2^20 long, I doubt you'll have any
problems for the foreseeable future.
"Wade G. Pemberton" wrote:
[color=blue]
> Richard Cornford wrote:
>
> I can tell from experience it's not 1024. The last string I used was over
> 23K bytes. However, I just wanted to make sure the limit wasn't something
> like 2^16, which I'll collide with shortly. It's just a packing script
> to export to MS Access from webdom. Since javascript has C as it's
> progenitor, that's probably the limit. I've forgotten that limit, and
> there's no book handy.
>
> Wade
>[color=green]
> > "Douglas Crockford" <nospam@laserli nk.net> wrote in message
> > news:9a027$3fa7 c56d$44a4aebc$9 152@msgid.megan ewsservers.com. ..
> > <snip>[color=darkred]
> > >... . The maximum length with will be implementation-specific. ...[/color]
> >
> > In microsoft.publi c.scripting.jsc ript, Michael Harris
> > (Microsoft.MVP. Scripting), who might be expected to know, quoted:-
> >
> > <quote Message-ID: <#CP34PocDHA.17 44@TK2MSFTNGP12 .phx.gbl>
> > In JScript, variant string variables have the same limit as in VBScript,
> > up to 2^31 characters.
> >
> > String *literals* (as in "this is a literal") have (IIRC) a limit ~2^10
> > (1024) characters.
> > </quote>
> >
> > - for the JScript implementation.
> >
> > Richard.[/color][/color]
--
| Grant Wagner <gwagner@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
* Internet Explorer DOM Reference available at:
*
Gain technical skills through documentation and training, earn certifications and connect with the community
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Comment
Comment