In Visual C++, if I use new to create an object on the heap, how much extra space is taken for the heap frame header and padding, specifically in release code? I'd expect an int to say how much space was available in the block, and another perhaps to say how much of that space was currently in use, and that frame sizes are rounded to the nearest 32 or 64 bits based on architecture. Just wondering does VC++ add anything extra like guard bytes, flags, etc... and are frame sizes rounded to a larger minimum size. Put another way, for large amounts of data, how inefficient is it to use a large number of small blocks of data on the heap.
Asked
Active
Viewed 461 times
1 Answers
6
Hackety-hack:
int* p = new int;
int* q = new int;
std::cout << (char*)q - (char*)p << std::endl;
Yes I know, technically undefined behavior, but I think it should answer the question :)

fredoverflow
- 256,549
- 94
- 388
- 662
-
Always the simple ones you miss. Thanks Fred! – SmacL Jun 15 '11 at 10:58
-
Very nicely answered; wish I could give you +2 for it! – Daniel Chisholm Jun 15 '11 at 17:50
-
@Daniel: Well, you could pick any other random answer from me and upvote that ;-) just kidding – fredoverflow Jun 15 '11 at 18:49