Unite with prev memory block
This commit is contained in:
parent
664d68a2dc
commit
c28179f9d4
2 changed files with 23 additions and 3 deletions
17
axl_memory.c
17
axl_memory.c
|
|
@ -109,4 +109,21 @@ void axl_free(void* ptr)
|
||||||
block->size += next_block->size + MB_HEADER_SIZE;
|
block->size += next_block->size + MB_HEADER_SIZE;
|
||||||
block->next = next_block->next;
|
block->next = next_block->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(block != root)
|
||||||
|
{
|
||||||
|
for(mb_header* mb = root; mb != NULL; mb = mb->next)
|
||||||
|
{
|
||||||
|
if(mb->next == block)
|
||||||
|
{
|
||||||
|
if(mb->is_free)
|
||||||
|
{
|
||||||
|
mb_header* prev_free_mb = mb;
|
||||||
|
prev_free_mb->size += block->size + MB_HEADER_SIZE;
|
||||||
|
prev_free_mb->next = block->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
main.c
9
main.c
|
|
@ -1,15 +1,18 @@
|
||||||
#include "axl.h"
|
#include "axl.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
int _start(void) // Entry point on Linux
|
int _start(void)
|
||||||
{
|
{
|
||||||
MessageBoxA(NULL, "wawa", "fffff", MB_OK | MB_ICONINFORMATION);
|
|
||||||
axl_init();
|
axl_init();
|
||||||
|
|
||||||
|
void* fds = axl_malloc(83);
|
||||||
|
|
||||||
int* f = axl_malloc(sizeof(int));
|
int* f = axl_malloc(sizeof(int));
|
||||||
*f = 4;
|
*f = 4;
|
||||||
|
axl_free(fds);
|
||||||
axl_free(f);
|
axl_free(f);
|
||||||
|
|
||||||
|
(void)fds;
|
||||||
(void)f;
|
(void)f;
|
||||||
|
|
||||||
Sleep(2);
|
Sleep(2);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue