On Aug 25, 2008, at 8:26 PM, Graham Cox wrote:

On 25 Aug 2008, at 11:56 pm, Graff wrote:

I have a large class I'm archiving that I would like to lazy-load. It's basically a wrapper around a NSArray and what I'd like to do is load some instance variables but leave the array archived until a later time in order to save time and memory.

How large are you talking about?

Have you actually profiled to see whether there is some genuine reason for wanting to do this, or are you just going on a "gut feeling" that it might be slow?

I'm not sure whether NSCoder preloads the entire archive into memory or not, but if it does and you retain the coder, you won't be saving time and memory anyway - in fact it could be worse on memory - much worse if your archive uses XML format.

I'm currently using a keyed archive to archive an NSArray of about 300,000 objects. On disk the archive takes up around 40MB. If I load a smaller archive there is a noticeable difference in load times, I don't have any numbers to throw around but it was enough that I thought it was worth trying to optimize.

A bit of background here, I am creating images based on computed color values for each pixel. I was originally creating NSColor objects on- the-fly to correspond to these values but that was very slow so I moved on to using NSColorList, using the computed value of the pixel to look up the appropriate color in the color list. NSColorList worked well for a small number of colors but when I tried to create larger color lists it bogged down very quickly. I then moved to a NSArray of NSColor objects where the index was a hash of the color value. This was quick and decently compact. I archived the NSArray to create several color arrays for different coloring schemes.

What I want to do now is to tag each color array with some metadata like the title of the color scheme or the bit depth of the image. I figured I would do this with a wrapper class for NSArray so that I could have a handy class to encapsulate all of the necessary methods and data. The stumbling block right now is how to easily get the metadata for several of these color array objects without having to load them all entirely into memory every time I just need the metadata.

Any suggestions on any of this mess? :)

- Ken Bruno
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to