On 10 Jul '08, at 11:29 AM, Jules Colding wrote:
Assume that I want to store the set {"HI", "HELLO"}. At one point I want to be able to use "HI" as key and get "HELLO". At another point I want to use "HELLO" as key and get "HI".There are several trivial ways to do this. I could use two NSDictionary's and use the NSCopying protocol to store both. Unfortunately that will make at least one, possibly both, dictionaries present in memory at query time.
You mean NSCoding, not NSCopying, right?The overhead for two dictionaries as opposed to one shouldn't be too high. Hash-table overhead is something like 4*sizeof(void*) bytes times the number of keys. It's the strings themselves that will take up most of the memory, and those are shared between dictionaries.
On the other hand, if the overhead of even one copy of the data in memory is too high, archiving isn't the way to go.
The best solution seems to be some kind of lightweight database... Is there any cocoa framework that implements a simple database or should I manually seek through a file?
The typical solution for this is SQLite, which is present in 10.4 and later. For simple things like what you're describing, it's not hard to use (though it is a C API, and you need to learn SQL to query it.) There are some Cocoa adapter libraries such as QuickLite and FMDB.
Another possibility is to use my CDBStore utility <http://mooseyard.com/projects/CDBStore/ >. It's a Cocoa wrapper around CDB, a very lightweight persistent dictionary file-format. It's not as powerful as SQLite, but for storing simple key/value dictionaries, especially ones that don't change too often, it's a lot lighter-weight.
—Jens
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) 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]
