Re: Lazy Loading Archive
Re: Lazy Loading Archive
- Subject: Re: Lazy Loading Archive
- From: Graff <email@hidden>
- Date: Mon, 25 Aug 2008 21:26:33 -0400
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 (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