malloc.c
static union Header *alloc_block(size_t block_size)
{
	union Header *block;

	/* ensure minimum allocation size */
	if (block_size < MIN_ALLOC) {
		block_size = MIN_ALLOC;
	}

	/* use sbrk to extend the heap */
	block = sbrk((intptr_t) block_size);
	if (block == (void *)-1) {
		return 0;
	}

	/* Append block to list */
	block->h.next = 0;
	if (s_head == 0) {
		/* first allocation */
		s_head = s_tail = block;
		block->h.prev = 0;
	} else {
		/* append block at tail of list */
		s_tail->h.next = block;
		block->h.prev = s_tail;
		s_tail = block;
	}
	block->h.size = block_size;
	block->h.flags = 0;

	return block;
}
/*
 * Allocate a new block using sbrk and append it to the list of blocks.
 * Returns the pointer to the allocated block, or null if
 * sbrk couldn't allocate more memory
 */
Allocate a new block using sbrk and append it to the list of blocks.
Returns the pointer to the allocated block, or null if
sbrk couldn't allocate more memory
Allocate a new block using sbrk and append it to the list of blocks . Returns the pointer to the allocated block or null if sbrk couldn ' t allocate more memory
static union Header *alloc_block(size_t block_size)
{
	union Header *block;
	if (block_size < MIN_ALLOC) {
		block_size = MIN_ALLOC;
	}
	block = sbrk((intptr_t) block_size);
	if (block == (void *)-1) {
		return 0;
	}
	block->h.next = 0;
	if (s_head == 0) {
		s_head = s_tail = block;
		block->h.prev = 0;
	} else {
		s_tail->h.next = block;
		block->h.prev = s_tail;
		s_tail = block;
	}
	block->h.size = block_size;
	block->h.flags = 0;
	return block;
}
static union Header * alloc_block ( size_t block_size ) { union Header * block ; if ( block_size < MIN_ALLOC ) { block_size = MIN_ALLOC ; } block = sbrk ( ( intptr_t ) block_size ) ; if ( block == ( void * ) -1 ) { return 0 ; } block -> h . next = 0 ; if ( s_head == 0 ) { s_head = s_tail = block ; block -> h . prev = 0 ; } else { s_tail -> h . next = block ; block -> h . prev = s_tail ; s_tail = block ; } block -> h . size = block_size ; block -> h . flags = 0 ; return block ; }
Allocate a new block using sbrk and append it to the list of blocks.
Allocate a new block using sbrk and append it to the list of blocks .
/* ensure minimum allocation size */ /* use sbrk to extend the heap */ /* Append block to list */ /* first allocation */ /* append block at tail of list */