• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Storing structured data in file - any easy way?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Storing structured data in file - any easy way?


  • Subject: Re: Storing structured data in file - any easy way?
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 10 Jul 2008 13:50:36 -0700


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

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

_______________________________________________

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

  • Follow-Ups:
    • Re: Storing structured data in file - any easy way?
      • From: Jules Colding <email@hidden>
References: 
 >Storing structured data in file - any easy way? (From: Jules Colding <email@hidden>)
 >Re: Storing structured data in file - any easy way? (From: Graham Cox <email@hidden>)
 >Re: Storing structured data in file - any easy way? (From: Jules Colding <email@hidden>)

  • Prev by Date: Re: Problem copying pdfImageRep to bitmapRep.
  • Next by Date: Re: Intercepting Apple Events
  • Previous by thread: Re: Storing structured data in file - any easy way?
  • Next by thread: Re: Storing structured data in file - any easy way?
  • Index(es):
    • Date
    • Thread