How much memory is needed for metadata when using the new int [10]?

When an array is created using the "new" and deleted using the delete operator, delete knows the size of the array. As mentioned in other SO streams, this size information is stored in metadata.

My question is: what exactly is stored in the metadata and how much space is needed for this? Is this just the size that is stored in the metadata?

+3
source share
4 answers

According to C ++ 5.3.4 / 12 standard:

new T[5] results in a call of operator new[](sizeof(T)*5+x), 

<...> where x are non-negative indefinite values ​​representing array distribution costs. <...> The amount of overhead can vary from one call of a new one to another.

+8

. , , "" "" . "" , , ..

. , , int[10] ( 40 ), , (, 24 , 32 - , .

, , , , , .

+4

. -. , , , .

, , . .

0

. malloc() , , . , glibc malloc:

http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=malloc/malloc.c;hb=HEAD

Minimum overhead for each allocated block: 4 or 8 bytes

  Each malloced chunk has a hidden word of overhead holding size
  and status information.
0
source

Source: https://habr.com/ru/post/1751137/


All Articles