On 23/07/2009, at 3:41 PM, Alexander Bokovikov wrote:
My specifics is that the data (strings) are delivered by an
external procedure, located out of ObjC stuff, and returning C-style
strings. My table has only one column. My question is, as usual,
about memory manager: May I write something like this:
exern void getString(int row, char *s, int *len);
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex {
char buf[255];
int len;
getString(rowIndex, buf, &len);
return [NSString stringWithCString:buf length:len
encoding:NSUTF8StringEncoding];
}
I.e. is it possible to return a NSString without its preliminary
retaining?
Or should I add [... retain] to the returning string?
Yes, that is the correct thing to do - you don't own the string, so
you shouldn't retain it.
BTW, watch out for a potential buffer overflow in getString(...), this
is the sort of thing viruses readily exploit.
--Graham
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com