• 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: speed of alloc/init for NSNumber
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: speed of alloc/init for NSNumber


  • Subject: Re: speed of alloc/init for NSNumber
  • From: Chuck Soper <email@hidden>
  • Date: Sun, 18 Jan 2004 14:30:21 -0800

At 1:24 PM -0800 1/18/04, mmalcolm crawford wrote:
On Jan 18, 2004, at 12:54 PM, Chuck Soper wrote:

I have an NSTableView with about 400 rows and four columns. I manage the content with an array of dictionaries. Some key values I display in each of the columns. One of the dictionary keys contains a single floating point number that has to be updated frequently.

Are you able to be more specific about "frequently"? And in particular how frequently compared to how often the value needs to be displayed in the table view?

The value is used to maintain sort order (if its column header is selected) so I have to update all the rows in the table instead of just the rows that are being being displayed. The values change based on certain user actions such as moving a slider bar. So, when I say frequently it could be every couple of seconds (while the user is moving a control and I have to maintain sort order) or not at all.

Since NSNumber doesn't have an mutable version, I have to release and alloc/init it every time I update the number. Should I use NSMutableData to avoid all the alloc/init messages to NSNumber to speed up my code?

The first questions should probably be, how slow is your code at the moment, and are you sure this is the bottleneck? If you put everything into an NSMutableData, presumably you'll incur additional overheads elsewhere...?

If you do decide it's worth using an int instead of an NSNumber, you might consider using a custom class to represent your data. In your table view data source method you can (still) use valueForKey: to get the int values -- they'll be automatically turned into NSNumbers for you...

mmalc

My question may have been more theoretical than practical. I don't have a noticeable slowdown at the moment, I just want to write fast code. I think that I may stick with using the release and alloc/init NSNumber messages until I have a quantifiable reason to optimize my code. I now know that I can write a custom class, but I agree with Daryn about being "dismayed by the absence of certain mutable classes".
Chuck
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >speed of alloc/init for NSNumber (From: Chuck Soper <email@hidden>)
 >Re: speed of alloc/init for NSNumber (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: speed of alloc/init for NSNumber
  • Next by Date: How can I accept directory drops to my app icon?
  • Previous by thread: Re: speed of alloc/init for NSNumber
  • Next by thread: Re: speed of alloc/init for NSNumber
  • Index(es):
    • Date
    • Thread