• 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: Temporary Strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Temporary Strings


  • Subject: Re: Temporary Strings
  • From: glenn andreas <email@hidden>
  • Date: Wed, 24 Aug 2005 16:43:59 -0500


On Aug 24, 2005, at 11:25 AM, Paul Harvey wrote:

I have a loop that uses NSRanges to look in a large string for certain occurences of characters and keeps a count of how many are found.

I'm looking for {1, {2, {3, {4.... and so on. I use a loop for the integer and create an NSString in side the loop

My question:

is it necessary to create a new NSString for each one? It seems wasteful to me. What I would like to do is simply pass "{" and concatenate the integer value to it. Is this possible?

The short answer "don't worry about it" (let's face it - even if you're looking at something huge, there's not going to be more than a couple hundred extra objects created) - if performance sampling shows it's a problem, then deal with it.


The medium answer - you can create an autorelease pool inside the loop and empty it periodically (say every 100 iterations). This is useful if you are making much bigger things, or if you may be iterating 10,000 times, for example.

The long answer. Switch to using NSScanner - for what you are trying to do (find the highest number), you can just scan through the string once, scanning up to the next "{" and then scanning in the integer that follows it. Keep track of the highest number you find. This will be more efficient than having to search through your string repeatedly for each one (though this exact algorithm will behave slightly differently if there area "missing" numbers since it would find the highest one regardless, where as your current one stops at the first gap found).


Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Temporary Strings (From: Paul Harvey <email@hidden>)

  • Prev by Date: c style array of float in Core Data
  • Next by Date: Re: Changing the Project Name in XCode
  • Previous by thread: Re: Temporary Strings
  • Next by thread: Distributed Objects and thread cleanup
  • Index(es):
    • Date
    • Thread