Visual C ++中的堆框架有多大 [英] How big is a heap frame in Visual C++

查看:113
本文介绍了Visual C ++中的堆框架有多大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual C ++中,如果我使用new在堆上创建对象,那么堆帧头和填充会占用多少额外空间,特别是在发布代码中?我希望一个int会说出块中有多少可用空间,或者可能要说出当前正在使用该空间中的多少,并且帧大小会根据体系结构四舍五入到最接近的32位或64位.只是想知道VC ++是否添加了额外的内容(例如保护字节,标志等),并且将帧大小四舍五入为更大的最小大小.换句话说,对于大量数据,在堆上使用大量小数据块效率低下.

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.

推荐答案

Hackety-hack:

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

这篇关于Visual C ++中的堆框架有多大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆