What is the "real" amount of memory occupied by a dynamic array?

Example:

procedure Test;
var
  AText: array of AnsiChar;
begin
  SetLength(AText, 7);
end;

Question

What is the real size of AText used in memory? Is it 7 + the cardinal size of its length, that is, 7 + 4 = 11 bytes?

+5
source share
1 answer

This is plus 4 bytes of reference counting. And, of course, the heapmanager overhead (which depends on the delphi version and uses a memory manager, which can easily be 12-16 bytes).

So this means:

  • sizeof (element) * elementcount
  • SizeOf (RefCount)
    • current implementations: sizeof (integer) = 4
  • SizeOf (elementnumber)
    • FPC actually stores the highest element, not the element. I do not know about Delphi)
    • current implementations: sizeof (integer) = 4
  • overhead.
    • , .
    • , ( ). .
    • 16 32.
+5

All Articles