On Sat, Nov 1, 2008 at 4:31 AM, Oleg Krupnov <[EMAIL PROTECTED]> wrote: > In my app all model data are saved in a single file. For the purpose > of optimizing file I/O, I'm looking for a solution that would not > force me to resave the entire model when only a tiny bit of it has > changed, and also allow loading (fetching) the model only partially - > lazily upon request. > > A solution for this problem could be saving different parts of the > model in different archive files using > NSKeyedArchiver/NSKeyedUnarchiver. However, this only works when there > are no cross-references between the parts of the model that need to be > saved. AFAIU, upon loading, any saved cross-reference would create a > new copy of the object that would not map to the same model object. Is > there a work around this problem? > > Another solution that seems feasible is a kind of file mapping into > memory, i.e. there is a single large file but accessed randomly like > memory. However, I am not sure there is such thing in Cocoa and also > if it really gives any performance gain. > > I'd appreciate any ideas.
If you can, you're probably better off using a file format and code that has already been written to do this job. Custom formats are already annoying and difficult to work with, and custom formats that don't need global updates for changes are even worse. For starters, CoreData will do this if you use it with the SQLite store format. If you can use CoreData then this should do the trick for you nice and easily. SQLite all by itself is also a good choice. If you aren't familiar with it, it's a full SQL database implemented as a single file with a relatively small open source (and usable in proprietary applications) C library. If you really want a custom format, my first thought is to use some sort of journalling approach. Write your file in such a way that you can simply append new data onto the end without having to modify any of the earlier parts of the file. You could write out changes at the end with some framing to indicate where the boundaries are, then when you load you simply start at the beginning and work your way through, applying changes as you go. This will obviously cause your file to grow without bound, so from time to time you'll want to clean house and save a fresh version from scratch. I believe this is how Microsoft Word works, or at least can work in some circumstances. Hope this helps. Mike _______________________________________________ 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]