Re: Initializing an Array
Re: Initializing an Array
- Subject: Re: Initializing an Array
- From: Jeff Galyan <email@hidden>
- Date: Tue, 22 Jan 2002 15:06:32 -0700
On 1/22/02 2:57 PM, "John C. Randolph" <email@hidden> wrote:
>
>
Okay, in the interest of making your life easier:
>
>
1) since you're going to be done with the c string before you
>
return from the method where you're creating it, go ahead and
>
use -cString instead of -getCString:.
>
>
- (const char *)cString
>
>
Returns a representation of the receiver as a C string in the
>
default C string encoding. The returned C string will be
>
automatically freed just as a returned object would be released;
>
your code should copy the C string or use getCString: if it
>
needs to store the C string outside of the autorelease context
>
in which the C string is created.
I tried this, and it *always* causes a segfault on my box.
>
>
and
>
>
2) if you need to find the length of an NSString in order to
>
manually allocate space for it's c-string representation, use
>
-cStringLength, not -length.
I didn't know about this method - thanks!
--Jeff