Added ralloc function.

This commit is contained in:
Arron David Nelson 2024-02-08 17:47:44 -08:00
parent c0da3fdefe
commit 103277bf63

5
main.c
View File

@ -4,6 +4,7 @@
#define ALIGN4(s) (((((s)-1)>>2)<<2)+4) #define ALIGN4(s) (((((s)-1)>>2)<<2)+4)
#define BLOCK_SIZE sizeof(struct block) #define BLOCK_SIZE sizeof(struct block)
#define MINIMUM_BLOCK_SIZE 16
/// The memory block's header. /// The memory block's header.
struct block struct block
@ -22,6 +23,10 @@ struct block* last = NULL;
/// @returns The new memory block. /// @returns The new memory block.
struct block* extend_heap(size_t s) 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); struct block* b = sbrk(0);
if (sbrk(BLOCK_SIZE + s) == (void*)-1) if (sbrk(BLOCK_SIZE + s) == (void*)-1)