• 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: RS: appendFormat allocation implications
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RS: appendFormat allocation implications


  • Subject: Re: RS: appendFormat allocation implications
  • From: Bill Bumgarner <email@hidden>
  • Date: Sat, 2 Jun 2007 20:36:08 -0700


On Jun 2, 2007, at 7:03 PM, Dominik Pich wrote:
On Jun 3, 2007, at 3:46 AM, Roland Silver wrote:

A question about the NSMutableString method appendFormat:

Does the "constructed string" which is added to the receiver exist as an allocated object after the appendFormat is complete?

E.g. after performing
	NSMutableString* s = [[NSMutableString stringWithString:@"foo"];
	[s appendFormat:@"%c", 'a'];

is there a garbage string @"a" floating around, waiting to be autoreleased?

Appended strings are retained by the String object and inherit its lifetime.

Not really.

(1) Appended strings are just that -- appended to the mutable string that is the target, in this case the string s. The argument that is appended will have whatever lifespan it had before the call, nothing more or less.

(2) The above code isn't appending a string. It is appending a character. As such, the 'c' will be stored in whatever spot the compiler decides is appropriate for a statically allocated character. On i386, the compiler emits " movl $97, 12(%esp)" to load the character 'a' into the slot for the 4th argument.

(3) The invocation of +stringWithString: will create an autoreleased mutable string. Use +alloc, -initWithString: if you want to avoid that.

b.bum

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >RS: appendFormat allocation implications (From: Roland Silver <email@hidden>)
 >Re: RS: appendFormat allocation implications (From: Dominik Pich <email@hidden>)

  • Prev by Date: Re: Building Paths (was Enabling NSButton)
  • Next by Date: Problem applying texture to rectangle.
  • Previous by thread: Re: RS: appendFormat allocation implications
  • Next by thread: Problem applying texture to rectangle.
  • Index(es):
    • Date
    • Thread