c++ - Extreme memory usage for individual dynamic allocation -


Here under Windows 7 I have done a simple test on MSVC ++ 2010:

  // structure with a Sizeof (s) == 4, such as 4 bytes of stratus {int x; }; // 1 million strikes allotted * test1 = new [1000000]; // Memory usage shows that the memory increase is expected to be around 4 bytes * 1000000 - like now! If I run it: For (Int i = 0; I <1000000; i ++) New S (); // Memory usage is inconsistent when it is divided by 1000000, 64 bytes per s !!!  

Is this a common knowledge or am I forgetting something? Before I was always used to make objects on the fly when needed, for example, in a trap, for every triangle the new triangle (), etc.

Is really the size of magnitude for the dynamic memory allocation of different instances? Edit Cheers

:

Using G ++, compiling and running the same program while working on Windows XP: now overhead 16 Is bytes, not 64, as seen before! Very interesting

Not required, but the operating system will usually reserve memory on your behalf in whatever size It is convenient; On your system, I thought it gives you multiples of 64 bytes per request.

There is an overhead associated with keeping a track of memory allocation, finally, and is not reserved in very small amounts.


Comments