什么是“真实”?动态数组占用的内存大小? [英] What is the "real" memory size occupied by a dynamic array?
本文介绍了什么是“真实”?动态数组占用的内存大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
procedure Test;
var
AText: array of AnsiChar;
begin
SetLength(AText, 7);
end;
问题
什么是 AText 的> real 大小?它是长度的7 +基数大小,即7 + 4 = 11个字节吗?
Question
What is the real size of AText occupied in memory? Is it 7 + Cardinal size of its length, that is, 7 + 4 = 11 bytes?
推荐答案
加上4个字节的引用计数。当然还有heapmanager的开销(取决于delphi版本和使用的内存管理器,可以很容易地为12-16字节)。
That plus 4 bytes reference count. And of course heapmanager overhead (which depends on delphi version and uses memory manager, which can easily be 12-16 bytes).
所以这意味着:
- sizeof(element)* elementcount
- sizeof(refcount)
- 当前实现:sizeof(integer)= 4
- FPC实际上存储的是最高元素,而不是elementcount。不知道Delphi)
- 当前实现:sizeof(integer)= 4
- 至少为整个块分配大小。
- 可能也有一个或两个指针(下一个块)。但这取决于内存管理器。
- 很多内存管理器的最小块大小为16或32。
这篇关于什么是“真实”?动态数组占用的内存大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文