Freeze on no memory available

This commit is contained in:
IlushaShurupov 2023-07-24 20:39:28 +03:00
parent 5f186164a0
commit 00bc875846

View file

@ -6,6 +6,7 @@
#include "Utils.hpp" #include "Utils.hpp"
#include "Debugging.hpp" #include "Debugging.hpp"
#include <cstdio>
#include <cstdlib> #include <cstdlib>
using namespace tp; using namespace tp;
@ -66,13 +67,17 @@ void* HeapAllocGlobal::allocate(ualni aBlockSize) {
} }
// 1) Allocate the block // 1) Allocate the block
ALLOCATE:
auto head = (MemHead*)malloc(aBlockSize + WRAP_SIZE * 2 + HEAD_SIZE); auto head = (MemHead*)malloc(aBlockSize + WRAP_SIZE * 2 + HEAD_SIZE);
if (!head) {
printf("WARNING : Cant allocate memory. Trying again\n");
goto ALLOCATE; // Just freeze if no memory is available
}
auto wrap_top = (int1*)(head + 1); auto wrap_top = (int1*)(head + 1);
auto data = wrap_top + WRAP_SIZE; auto data = wrap_top + WRAP_SIZE;
auto wrap_bottom = data + aBlockSize; auto wrap_bottom = data + aBlockSize;
if (!head) { return nullptr; }
head->mBlockSize = aBlockSize; head->mBlockSize = aBlockSize;
head->mIgnored = mIgnore; head->mIgnored = mIgnore;