1

I have serialized a map using QDataStream and written the object into a file.

The serialized file size is 1.5mb when i deserialize it again and load the map into memory, the memory consumption was 300mb. I have used the same QDataStream to deserialize.

Can you let me know the reason why deserialization of the 1.5mb serialized object written to a file on disk took 300mb in the memory.

Serialization:

QMap< QString, QSet< QString > >  myMap[100];
QSet<QString> mySet; // Assume it has some data in it.
QSet<QString> mySet1; // Assume it has some data in it.
MyMap.insert("a", mySet);
MyMap.insert("b", mySet1);
QFile f( strOutFile );
f.open(QIODevice::WriteOnly);
QDataStream streamOut( &f );
streamOut << myMap;

Deserialization:

QFile f(StrInFile);
QMap< QString, QSet< QString > >  InMap[100];
QDataStream streamIn( f, QIODevice::ReadOnly );
streamIn >> InMap[index];

I have checked the memory consumption using MEMORYSTATUSEX windows library. After deserializing, the memory consumed was 300 mb.

Thanks for the Help.

aditya
  • 21
  • 2
  • What is the question? Could you create a simple app which reproduces the problem? – Ezee Oct 10 '14 at 09:59
  • How do you measure memory consumption?? – UmNyobe Oct 10 '14 at 10:06
  • There is something wrong with the code. What is `MyMap`? I do not see it declared. furthermore, you are serialising just a pointer to myMap (this is what a stack array identifier is: a pointer) and I cannot grasp how you are getting 1,5MB file this way. However, even if you have defined template to overload `operator<<` to accept a pointer to `myMap` type you are still writing just one object of 100. Of course file may easily be much smaller than a set of 100 empty objects. – Euri Pinhollow Feb 16 '17 at 08:05
  • Seeing `index` in second part suggests that you are doing more than you have written here but I cannot be sure. – Euri Pinhollow Feb 16 '17 at 08:14

1 Answers1

0

There is something wrong with the code. What is MyMap? I do not see it declared. Furthermore, you are serialising just a pointer to myMap (this is what a stack array identifier means: a pointer) and I cannot grasp how you are getting 1,5MB file this way.

However, even if you have defined template to overload operator<< or just overloaded operator<< to accept a pointer to myMap type (that three-fold class tree in the beginning) you are still writing just one object of 100. Of course file may easily be much smaller than a set of 100 empty objects.

I will update my answer if I see more explanations from you.

Euri Pinhollow
  • 332
  • 2
  • 17