Re: Saving *lots* of instances to disk
Re: Saving *lots* of instances to disk
- Subject: Re: Saving *lots* of instances to disk
- From: Matt Neuburg <email@hidden>
- Date: Wed, 26 Jan 2005 12:04:14 -0800
On Wed, 26 Jan 2005 03:57:43 -0700, "Kiel Gillard" <email@hidden>
said:
>Hey guys,
>
>I'd like to know what you guys think I could do about my situation here: I have
2 mutable dictionaries and 1 mutable array which i need to save to disk, so
users can restore these instances the next time they start up my program.
>
>Each collection contains instances/objects of custom classes I've made, and
each object contains one or many arrays, dictionaries and multiple
strings/numbers/attributed strings.
>
>I currently use +[NSKeyedArchiver archiveRootObject: toFile:] to archive a root
object which contains two dictionaries with 30 keys and values and 2 objects in
the mutable array. This takes about .25 of a second to save everything to one
file. Realistically, I'm looking at many times more objects being used - 500 odd
in one dictionary and about 1500 in another.
>
>I've thought of the following options I could take to work around the delay:
>1) Breaking the file into a file for each collection - but it will still take
an unacceptable amount of time.
>
>2) Calling the save method in a thread - is this a good idea? I'll obviously
have to use NSLocks to prevent the data changing on the thread.
>
>3) In a thread, saving the 3 different collections independently, depending on
which one was changed.
>
>Is there any other options I could use?
Yes - don't use keyed archiving. The speed (or lack of it) or keyed
archiving has been discussed here many times.
<http://www.cocoabuilder.com/archive/message/2003/9/24/1965>
Since what you've got is arrays, dictionaries, and strings, I would just
save using NSPropertyListSerialization. In my app, that's spectacularly
faster than using keyed archiving. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
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