vendredi 1 juillet 2016

Memory footprint for the same number of objects

class A {};
class B {};
Both the classes are properly defined.

struct MyStruct{
typedef std::vector< std::pair< const A*, const B* > > TVec;
std::map< std::string, TVec > d_data;
};

Now i have a 2D array of 10X10 where each element of my 2D array is of type struct MyStruct.

Now i have 100 elements to add in this 2D array. If each element is inserted at unique position in array, in that case, my memory footprint is, let say 'X' MB. each 2D array element contains exactly one MyStruct element stored.

But if i add all the 100 elements of type MyStruct at last position i.e. 2DArr[9][9], my memory footprint is, let say 'Y' MB.

Assume that map size is 1 i.e. there is only 1 key and corresponding to that key, multiple values are stored in a vector.

What i see is, 'Y' is close to 4 times greater then 'X' Why it is as at the end, i am inserting same number of elements i.e. 100 MyStruct elements in the 2D array but at different locations in both the cases.

Aucun commentaire:

Enregistrer un commentaire