Re: Max size of an NSString
Re: Max size of an NSString
- Subject: Re: Max size of an NSString
- From: "Alastair J.Houghton" <email@hidden>
- Date: Tue, 28 Oct 2003 16:41:37 +0000
On Tuesday, October 28, 2003, at 04:13 pm, Jvrn Salewski wrote:
Theoretically the maximum size of an NSString would be determined by
the
maximum size of its index to access the single unichar characters; this
index is defined as an unsigned int, so it would be UINT_MAX unichars.
Not necessarily. I think you'll find if you look closely that there is
more than one underlying implementation of NSString, and that the exact
type of object you get is dependent on the internal encoding used.
Therefor, on a 32bit machine you could store up to 4GB of characters
in an
NSString.
No, you couldn't. It wouldn't fit into the available address space.
Practically, with such a big string the computer would probably
stop responding because of vm swaping.
Only if you access it.
(serious question:) Has anybody ever tried this?
unichar *ptr = (unichar *)malloc(UINT_MAX * sizeof(unichar));
Will return NULL, because that number of characters don't fit into a
32-bit address space *at all*, without even considering the fact that
some of it is reserved by your program and by the operating system.
It is, perhaps, interesting to note that you can allocate stupid
amounts of "memory" on most modern platforms, even if there is
insufficient RAM and virtual memory to back the region allocated...
this happens because of an optimisation whereby the actual memory isn't
assigned to your program until you write to it. To give an example, I
once (because of a rather silly bug) allocated over 1GB of memory on a
Windows machine for a 16 x 16 bitmap ;-> The memory allocator gave me
a valid pointer, and the program worked, because I was only touching
the first page of the memory I'd reserved. I only spotted the problem
because another, unrelated, memory allocation was failing (which is
pretty unusual on modern systems).
am 28.10.2003 14:29 Uhr schrieb Arthur VIGAN unter
email@hidden:
What is the mximum size of an NSString?
I am trying to put the content of an HTML file of only 8KB in an
NSString, but the file is truncated...
I think your problem is related to some character in the file (like a
linebrake) that is interpreted as a terminating NULL charater '\n'.
The terminating NUL (which has one L, to distinguish it from NULL,
which is a pointer to location 0) is the character '\0', not '\n'.
'\n' is a line-feed. This is one possible reason for the problem
Arthur is having, although not the only one; for example, he may be
reading it from the file incorrectly.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.