• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTableView - populating from C procedure
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSTableView - populating from C procedure
      • From: Alexander Bokovikov <email@hidden>
References: 
 >NSTableView - populating from C procedure (From: Alexander Bokovikov <email@hidden>)

  • Prev by Date: NSTableView - populating from C procedure
  • Next by Date: Re: NSTableView - populating from C procedure
  • Previous by thread: NSTableView - populating from C procedure
  • Next by thread: Re: NSTableView - populating from C procedure
  • Index(es):
    • Date
    • Thread