Re: Is @"constantstring" pointer equal to @"constantstring" aguarantee?
Re: Is @"constantstring" pointer equal to @"constantstring" aguarantee?
- Subject: Re: Is @"constantstring" pointer equal to @"constantstring" aguarantee?
- From: Chris Hanson <email@hidden>
- Date: Fri, 28 Mar 2008 02:36:41 -0700
On Mar 27, 2008, at 8:39 PM, Jens Alfke wrote:
@"" strings are actually instances of an immutable private NSString
subclass. I think it's called _NSConstantString or some such.
Yup. And they're not allocated on the heap; they're stored in the
executable itself, although their memory layout is that of a "real"
Obj-C object. The compiler tags them in such a way that the linker
will coalesce identical ones into a single value.
It's slightly more complicated than that -- there's also GCC's "-fno-
constant-cfstrings" option, which will cause at least CFSTR()
constants (I'm not sure whether it also covers @"" constants) to be
created dynamically rather than statically.
This is important for developers of bundles which may be unloaded,
because a pointer to a constant string in an executable that's will
become a dangling pointer if that executable is unloaded.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden