Where is the "space itself" in the storage distributor described at the end of the K & R book?

At the very end of the book by Kernighan and Ritchie, written in the C programming language, a memory allocator is described. It says:

Each block contains a size, a pointer to the next block, and space in itself.

But I do not see this in the code:

typedef long Align;  /* for alignment to long boundary */

union header {       /* block header */
   struct {
      union header *ptr; /* next block if on free list */
      unsigned size;     /* size of this block */
   } s;
   Align x;          /* force alignment of blocks */
};

typedef union header Header;

Pointer to the next block *ptr, and the size unsigned size, but which variable is the space itself? Is space itself a variable x?

+4
source share
2 answers

. , , , sizeof (header), sizeof (header), . ( , , , Google Googled , , Java tutorials), :

, , ; "".. , , . , , [.]

. 186, 8, C,

, . 189, malloc() , :

void *malloc(unsigned nbytes)
{
    /* ... */
    nunits = (nbytes+sizeof(Header)-1)/sizeof(Header) + 1;

. 187, 8, C,

+3

. ( ):

8.7 -

[...]

malloc . , , malloc, . , . , .

, . 20 KiB , . int, 20 * 1024 * 1024, , 20 ( ), .

void *malloc(unsigned nbytes)
{
    nunits = (nbytes+sizeof(Header)-1)/sizeof(header) + 1;

, (Header), , .

+1

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


All Articles