c# string size limit? length of string limit?

c# string size limit? length of string limit?

Post by Danie » Thu, 20 Apr 2006 09:38:52


c# string size limit? length of string limit?
 
 
 

c# string size limit? length of string limit?

Post by Michael » Thu, 20 Apr 2006 09:50:23


Limit of available contiguous free memory block or 2^31 chrs.

 
 
 

c# string size limit? length of string limit?

Post by Jon Skeet » Thu, 20 Apr 2006 15:06:08


Not quite - I believe the top bits of the length are taken for extra
flags, and there's always an extra null terminator, so it's 2^30-1
chars. Not that I expect it'll make a difference to anyone :)

--
Jon Skeet - < XXXX@XXXXX.COM >
http://www.yqcomputer.com/ ~skeet Blog: http://www.yqcomputer.com/
If replying to the group, please do not mail me too
 
 
 

c# string size limit? length of string limit?

Post by Michael » Thu, 20 Apr 2006 15:40:45


Does C# use a null chr?
 
 
 

c# string size limit? length of string limit?

Post by Jon Skeet » Thu, 20 Apr 2006 16:12:33


C# itself doesn't need it - nor does most managed code, I believe.
(Unsafe managed code may use it for convenience, if it's sure there are
no null chars genuinely in the string.)

However, for interop reasons it's really handy to have the null char at
the end anyway - a pointer can be passed to any unmanaged code which
expects a null-terminated UTF-16-encoded string, without copying
anything.

Jon
 
 
 

c# string size limit? length of string limit?

Post by Willy Deno » Fri, 21 Apr 2006 00:21:45


| > > c# string size limit? length of string limit?
| >
| > Limit of available contiguous free memory block or 2^31 chrs.
|
| Not quite - I believe the top bits of the length are taken for extra
| flags, and there's always an extra null terminator, so it's 2^30-1
| chars. Not that I expect it'll make a difference to anyone :)
|
| --
| Jon Skeet - < XXXX@XXXXX.COM >
| http://www.yqcomputer.com/ ~skeet Blog: http://www.yqcomputer.com/
| If replying to the group, please do not mail me too

The CLR (currently) limits the size of an object to 2^31 bytes. That means
that the string buffer size is limited to (2^31 - size of the object header)
bytes, or 2^31-16 bytes or 2^30-8 = 1073741816 characters in .NET.

There is only a trailing null terminator if the buffer is large enough, in
the maximum case there isn't a null terminator.
Note that such string cannot be created on Windows 32 bit.

Willy.