Malloc and heap: additional memory for storing size information and related information?

I have a simple question about heapand malloc:

When we allocate some memory space using mallocas follows:

int *p;
p = (int*) malloc (10*sizeof(int));

It actually allocates 10 words per heap. However, my question is:

Actual usable memory space is 10 words?

Or is there other additional space needed to store the size of the memory?

Or, even because the heap is structured as a linked list, is there any other memory space that is used to store the address that points to the next node of the list on the heap?

+4
source share
4 answers

It is completely implementation dependent.

a) node, node, node , , node node.

b) , . , , , .

c) . 32- ; 128- .. .

d) , , free() (.. free() - op) malloc().


. b , NTFS FAT. c / DEC, . d .

( 2, 8, 16 ..), . , 5, 3, 8, 7, 4, 1 15 16 .

+7

.

, . , , - .

, - , .

, .

, , .

+2

, malloc , , , , . free , , , .

, , - , .

+1
source

When you allocate memory with malloc, all you get is a pointer to the first address in that memory and a guarantee that so many bytes have been allocated for your use. Information about how this memory is allocated and tracked depends on the platform, and you will not be able to access this information from the program. Therefore, when additional memory can be allocated for overhead purposes, you cannot use this knowledge in a cross-platform manner.

+1
source

All Articles