问题
Example:
procedure Test;
var
AText: array of AnsiChar;
begin
SetLength(AText, 7);
end;
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?
回答1:
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).
So that means:
- sizeof(element)*elementcount
- sizeof(refcount)
- current implementations :sizeof(integer)=4
- sizeof(elementnumber)
- FPC actually stores highest element, not elementcount. Don't know about Delphi)
- current implementations :sizeof(integer)=4
- heap overhead.
- At least the allocated size for the entire block.
- Probably one or two pointers also (next block). But this depends on memory manager
- many memory managers have a minimal blocksize of 16 or 32.
来源:https://stackoverflow.com/questions/4448897/what-is-the-real-memory-size-occupied-by-a-dynamic-array