On 2 May '08, at 3:29 PM, Angel Todorov wrote:

I want to serialize in an archive a set of objects (big ones) that are
instances of a class which implements NSCoding. On deserialization, I don't want the whole archive to be loaded in memory, but only the object for the
*key* that I am requesting.

Cocoa archiving doesn't do that; it always reads or writes the entire archive.

But by coincidence, I recently wrote a class that does exactly what you're asking. I've been meaning to announce its availability as open source, but kept getting sidetracked. Here it is:

http://mooseyard.com/projects/CDBStore/

CDBStore is a file-backed persistent dictionary. You can store and retrieve values using keys; only the values you ask for get read from the file, and only modified values get written back to the file. The values can be arbitrary archivable NSObjects. The keys are, by default, limited to NSData, but you can easily support other types of keys by overriding one method.

CDBStore is a kind of middle ground between simple property-lists or archived objects, and CoreData. There's a very large empty space there, and I kept getting annoyed by having to cobble together yet another bit of code to read and write a dictionary from a file.

Behind the scenes, CDBStore uses CDB, or "Constant DataBase", a simple persistence library. CDB is very efficient: usually no more than two reads to fetch any value, and the file is memory-mapped so it takes advantage of the kernel's caching. It's also very reliable: it never updates a file in place, so its files cannot get corrupted on a system crash the way SQLite or Berkeley DB databases can. On the other hand, it won't be nearly as efficient for large rapidly-updated data sets.

I've been using CDBStore for a few months now in the app I'm developing. I can't claim it's fully complete, but it's been working very well for me.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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