TombEngine/TR5Main/Global/malloc.cpp

43 lines
732 B
C++
Raw Normal View History

#include "framework.h"
2018-08-19 09:46:58 +02:00
#include "malloc.h"
#include "global.h"
2018-08-19 09:46:58 +02:00
2020-04-24 19:15:05 +02:00
char* malloc_buffer;
int malloc_size;
char* malloc_ptr;
int malloc_free;
int malloc_used;
2020-04-24 19:15:05 +02:00
char* game_malloc(int size)
2018-08-19 09:46:58 +02:00
{
2020-04-24 19:15:05 +02:00
char* ptr;
2018-08-19 09:46:58 +02:00
2020-04-24 19:15:05 +02:00
size = (size + 3) & 0xfffffffc;
if (size <= malloc_free)
2018-08-19 09:46:58 +02:00
{
2020-04-24 19:15:05 +02:00
ptr = malloc_ptr;
malloc_free -= size;
malloc_used += size;
malloc_ptr += size;
2018-08-19 09:46:58 +02:00
return ptr;
}
2020-04-24 19:15:05 +02:00
return 0;
2018-08-19 09:46:58 +02:00
}
2020-04-24 19:15:05 +02:00
void init_game_malloc()
2018-08-19 09:46:58 +02:00
{
2020-04-24 19:15:05 +02:00
malloc_size = 1048576 * 128;
malloc_buffer = (char*)malloc(malloc_size);
malloc_ptr = malloc_buffer;
malloc_free = malloc_size;
malloc_used = 0;
2018-08-19 09:46:58 +02:00
}
2020-04-24 19:15:05 +02:00
void game_free(int size, int type)
2018-08-19 09:46:58 +02:00
{
2020-04-24 19:15:05 +02:00
size = (size + 3) & (~3);
malloc_ptr -= size;
malloc_free += size;
malloc_used -= size;
2018-08-19 09:46:58 +02:00
}