How big is a heap frame in Visual C++

北城以北 提交于 2019-12-12 11:28:36

问题


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.


回答1:


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 :)



来源:https://stackoverflow.com/questions/6356222/how-big-is-a-heap-frame-in-visual-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!