Re: on NSString usage
Re: on NSString usage
- Subject: Re: on NSString usage
- From: Chris Hanson <email@hidden>
- Date: Thu, 1 Aug 2002 12:37:15 -0500
Chong Hiu Pun:
I think you need to take a step back and read some introductory
materials before trying to go further with your application. I
recommend starting with "Object-Oriented Programming and the
Objective-C Language" which is part of the developer documentation
Apple supplies. Then read "Cocoa Programming for Mac OS X" by Aaron
Hillegas. Read the entire book and do all the exercises. It's
become clear that you've only done the barest minimum possible amount
of research before starting a Cocoa project, and it's holding you
back.
To answer your specific question, constant NSStrings created with @""
don't need to be alloc'd, init'd, retained, released, etc. The
@"foo" construct essentially compiles down to a call to a function
like NSConstantStringForCString("foo"). Since "foo" is a constant C
string, it winds up in your executable's data segment, and
NSConstantStringForCString will return an instance of a special
subclass of NSString (call it "NSConstantCString") that just points
to that data internally. This hypothetical
NSConstantStringForCString will allocate an instance of the
hypothetical NSConstantCString class only once for each specific
constant C string, and will return the same instance each time it's
called with the same constant C string. Does this make sense?
-- Chris
--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
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.