Heap Memory
Management
FABRIKAM RESIDENCES
My Procedure
➢ The all heap is a FREE one block in the first.
➢ In runtime it converted to a doubly linked list.
➢ Each node in the doubly linked list is a block of memory.
➢ Each block can be FREE or NOT_FREE.
➢ The allocated and not allocated blocks have the same metadata.
➢ The used algorithm is the first-fit
Doubly linked list
➢ The structure content
typedef struct free{
void* address;//address of this block
struct free *next;//address of the next block
struct free *privios;//addres of the prev block
int size;//size of the block
block_state free;//status of the block
}free_list;
typedef enum {
FREE,
NOT_FREE
}block_state;
Functions:
➢ void initailiztion();
➢ free_list* SplitBlock(free_list* block,int size );
➢ void MerageTwoBlk(free_list* BlockOne,free_list* blockTwo);
➢ void* My_malloc(int size);
➢ void my_free(void* ptr);
➢ void* my_calloc(size_t num,size_t size);
➢ void* my_realloc(void* ptr, size_t newSize);
My_malloc flowchart
My_malloc flowchart
My_free function
My_free function
text
Initialize data
unInitialize data
Increasing address
Heap in Virtual memory.
Stack
argv
text
Initialize data
unInitialize data PB
block1
block2
block3
block4
Increasing address
Heap in Virtual memory.
Stack
argv
text
Initialize data
unInitialize data
block1
block2
block3
block4
PB
Increasing address
block5
block6
Heap in Virtual memory.
Stack
argv
text
Initialize data
unInitialize data
block1
block2
block3
block4
Increasing address
block5
Heap in Virtual memory.
PB
Stack
argv
text
Initialize data
unInitialize data
block1
block2
block3
block4
Increasing address
Heap in Virtual memory.
PB
Stack
argv
Split function
100 100
address next prev size free address next prev size free address next prev size free
Split function
100
address next prev size free address next prev size free
Split function
100 100
address next prev size free address next prev size free address next prev size free
Split function
200+ metadata size
address next prev size free address next prev size free
Test cases.
Test cases.
Test cases.
Test cases.(random allocating and freeing)
Moniem hmm VS glibc hmm
Bad News