33 lines
519 B
C
33 lines
519 B
C
//
|
|
// Created by Elias Bennour on 28.01.24.
|
|
//
|
|
|
|
#ifndef HEAP
|
|
#define HEAP
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
int maxHeapSize = 8192 * 1024;
|
|
|
|
void* my_malloc(size_t size) {
|
|
static size_t total_allocated = 0;
|
|
|
|
if (total_allocated + size > maxHeapSize) {
|
|
perror("Memory limit exceeded\n");
|
|
exit(1);
|
|
}
|
|
|
|
void* ptr = malloc(size);
|
|
if (ptr != NULL) {
|
|
total_allocated += size;
|
|
}
|
|
|
|
return ptr;
|
|
}
|
|
|
|
void initHeap(int size) {
|
|
maxHeapSize = size;
|
|
}
|
|
|
|
#endif //NINJA_NJVM_H
|