views:

606

answers:

2

I'm working on a basic editor application. It uses an array of varying size that I want to store to disk. This will eventually be in an AIR application, but for now it's just an AS3 project in Flex.

I want to store the array in a file. The application edits the data, so it doesn't need to be human readable. I want it to be in whatever format will be quickest to store and load back into the array when I need that data again.

Any recommendations? Thanks in advance!

Edit: It strikes me that importing/exporting in such a way that it can be immediately cast as an Array() would probably be the cheapest thing rather than some sort of iterating - if that's possible. Another obvious option is getting the data as a simple comma delineated string and using the String.split() function to get an array. Though again, the question is what would be cheapest - and I'm not quite convinced that's it.

I'll also add that it needs to be in some sort of permanent file, so a shared object - while possibly the fastest, isn't really a long term solution.

A: 

First, take a look at this answer.

As for saving the contents of an Array, consider JSON using the export tools provided by Adobe.

jedierikb
I'd want to see something promoting JSON as the fastest means of getting the contents back into an Array.
grey
+1  A: 

I think the fastest and easiest way is to use a shared object. It stores native objects, so there is no serialization / deserialization steps involved. Just assign the value and read it back.

Performance wise, probably the fastest route as well. If you are looking for a large dataset and are sure it's an AIR app, you can use AIR's db, but that will definitely take much more work.

Arthur Debert
Any ideas for something more permanent in some form of external file?
grey
Then you probably need to save this to some external file. You can probably write the shared objects bytes to disk (either offer as download on fp10, store in a server, or as a local file on an AIR app). Else, you'll need to have some serialization format (depending on your needs, JSON will be lightweight), but by then you are not using the "fastest" (runtime cost) way possible.
Arthur Debert
This seems reasonable. It *looks* like you can only save SharedObjects to the specific location for your application type. As such I think I'll probably have to convert it to a ByteArray and just use that to write to a file. Should still be reasonably quick. Thank you for the answer though. Good info.
grey