I have read here How does delete[] "know" the size of the operand array? that before the allocated memory it is saved how much memory it was allocated. I allocated an array of integers, set each element to value 15 and inspected the heap. First I allocated an array with 2 elements:
x/8xw 134524932
0x804b004: 0x00000011 0x0000000f 0x0000000f 0x00000000
0x804b014: 0x00020ff1 0x00000000 0x00000000 0x00000000
and another with 4 elements:
x/8xw 134524932
0x804b004: 0x00000019 0x0000000f 0x0000000f 0x0000000f
0x804b014: 0x0000000f 0x00000000 0x00020fe9 0x00000000
There are several things I do not understand:
1) How the values 0x00000011
and 0x00000019
define the size of the allocation?
2) Is there space for an extra array element allocated?
3) Are the values 0x00020ff1
and 0x00020fe9
at the of the allocated memory related to the allocation?
I am using gcc on a 32bit Ubuntu.