Re: NSTableView - populating from C procedure
Re: NSTableView - populating from C procedure
- Subject: Re: NSTableView - populating from C procedure
- From: Graham Cox <email@hidden>
- Date: Thu, 23 Jul 2009 15:52:33 +1000
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 (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