4

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.

trincot
  • 317,000
  • 35
  • 244
  • 286
SmacL
  • 22,555
  • 12
  • 95
  • 149

1 Answers1

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