tags:

views:

91

answers:

2

Hi everyone. I'm working on a project in Objective-c where I need to work with large quantities of data stored in an NSDictionary (it's around max ~2 gigs in ram). After all the computations that I preform on it, it seems like it would be quicker to save/load the data when needed (versus re-parsing the original file).

So I started to look into saving large amount of data. I've tried using NSKeyedUnarchiver and [NSDictionary writeToFile:atomically:], but both failed with malloc errors (Can not allocate ____ bytes).

I've looked around SO, Apple's Dev forums and Google, but was unable to find anything. I'm wondering if it might be better to create the file bit-by-bit instead of all at once, but I can't anyway to add to an existing file. I'm not completely opposed to saving with a bunch of small files, but I would much rather use one big file.

Thanks!

Edited to include more information: I'm not sure how much overhead NSDictionary gives me, as I don't take all the information from the text files. I have a 1.5 gig file (of which I keep ~1/2), and it turns out to be around 900 megs through 1 gig in ram. There will be some more data that I need to add eventually, but it will be constructed with references to what's already loaded into memory - it shouldn't double the size, but it may come close.

The data is all serial, and could be separated in storage, but needs to all be in memory for execution. I currently have integer/string pairs, and will eventually end up with string/strings pairs (with all the values also being a key for a different set of strings, so the final storage requirements will be the same strings that I currently have, plus a bunch of references).

In the end, I will need to associate ~3 million strings with some other set of strings. However, the only important thing is the relationship between those strings - I could hash all of them, but NSNumber (as NSDictionary needs objects) might give me just as much overhead.

A: 

If you can, rebuilding your application in 64-bit mode will give you a much larger heap space.

If that's not an option for you, you'll need to create your own data structure and define your own load/save routines that don't allocate as much memory.

Mark Bessey
This is incorrect; your GUI can be 64-bit as of Leopard.
Wevah
Or rather, part of that was incorrect. ;)
Wevah
Oops. For some reason u was thinking 64-bit GUI was a 10.6 feature. I've edited my answer.
Mark Bessey
A: 

NSDictionary isn't going to give you the scalable storage that you're looking for, at least not for persistence. You should implement your own type of data structure/serialisation process.

Have you considered using an embedded sqllite database? Then you can process the data but perhaps only loading a fragment of the data structure at a time.

AlBlue
Using a sqlite database worked. Thanks!
bobidden