Added ralloc function.
This commit is contained in:
parent
c0da3fdefe
commit
103277bf63
5
main.c
5
main.c
@ -4,6 +4,7 @@
|
||||
|
||||
#define ALIGN4(s) (((((s)-1)>>2)<<2)+4)
|
||||
#define BLOCK_SIZE sizeof(struct block)
|
||||
#define MINIMUM_BLOCK_SIZE 16
|
||||
|
||||
/// The memory block's header.
|
||||
struct block
|
||||
@ -22,6 +23,10 @@ struct block* last = NULL;
|
||||
/// @returns The new memory block.
|
||||
struct block* extend_heap(size_t s)
|
||||
{
|
||||
// Ensure the allocated size is at least the minimum block size
|
||||
if (s < MINIMUM_BLOCK_SIZE)
|
||||
s = MINIMUM_BLOCK_SIZE;
|
||||
|
||||
struct block* b = sbrk(0);
|
||||
|
||||
if (sbrk(BLOCK_SIZE + s) == (void*)-1)
|
||||
|
Loading…
Reference in New Issue
Block a user