tags:

views:

41

answers:

1

Hi all, i`am asking a new question, since the previouse one was in another purpose(the one on serializing)

I have a list of items which r binded to database, and i want to serialize the database rows to file (on runtime!!), and in the future to deserialize them. now as we know, i have to go through all the rows in my database and create new object to each row and serialize it to the file. the prob is that if we have 10000 rows in my database, then it's 10000 allocations of objects which eventually will be serialized.. any idea how to avoid this mass-allocation?

Thanks!

A: 

If you are worried about the number of allocations, you could serialize them in batches...then at the end serialize a "header" file that has the locations of the previous files and any other metadata.

After you are done with the first serialization, reuse those X allocations (from either an object pool or manually) for the next X allocations.

Rinse, repeat.

TimW
Oh i tried that, but it didnt work for some reason, i could deserialize them properly for some reason when i used the same object allocation for all the rows..
Moshik
Did you only have one object or a group of objects (i.e. 500) that you reused?
TimW