• 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: Creating strings in a loop - Efficiency Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating strings in a loop - Efficiency Question


  • Subject: Re: Creating strings in a loop - Efficiency Question
  • From: Roland King <email@hidden>
  • Date: Fri, 29 May 2009 00:32:25 +0800

well .. it's hard to say until you actually try it and profile your code however ..

I try to stick to something like 2. whenever it doesn't cause me to bend the code around too much. I use alloc/init .. use variable .. release whenever I can. Absolutely nothing guarantees that anything in the 'use variable' section won't put it on an autorelease pool and you gained nothing, but often enough, especially when 'use variable' is my own code, it doesn't and I feel this gives me the best shot at earliest release, dealloc and memory reclaim. I program mostly for the iPhone and so I make an effort to code in a way which previous analysis has shown tends to release memory as early as possible.

However, if you don't know if this is a bottleneck, do the thing which makes most coding sense and then profile it. It's quite possible for instance that on a device with loads of memory, adding 20,000 Strings and releasing them all at once in an AutoRelease pool is actually good.

On May 29, 2009, at 12:20 AM, Reza Farhad wrote:

Hi

I have a situation where I need to create a new string as I go through a loop.
What will be the most efficient way of doing this each time the call goes through the loop.


1. To create an auto releasing string.
2. To create a non auto-releasing string at the start of the loop and releasing it at the end of the loop.
3. To create a non auto-releasing mutable string before the loop and then at the start of the loop delete and reset it content to a new value. And obviously delete the string after the loop.


4. An alternative suggestion!!!!

Thanks in advance

Reza

_______________________________________________

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

_______________________________________________

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


References: 
 >Creating strings in a loop - Efficiency Question (From: Reza Farhad <email@hidden>)

  • Prev by Date: Re: performSelectorOnMainThread problem
  • Next by Date: Re: Triggering change notifications when modifying custom object ivars in core data app
  • Previous by thread: Re: Creating strings in a loop - Efficiency Question
  • Next by thread: Binding to two values
  • Index(es):
    • Date
    • Thread