mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-02 09:47:58 +03:00
Added new specifiers to memory functions
This commit is contained in:
parent
053953b8ab
commit
0c357de3d8
3 changed files with 9 additions and 8 deletions
|
@ -12,12 +12,12 @@ int malloc_used;
|
||||||
using namespace T5M::Memory;
|
using namespace T5M::Memory;
|
||||||
MemoryPool* gameMemory;
|
MemoryPool* gameMemory;
|
||||||
|
|
||||||
void init_game_malloc()
|
void init_game_malloc() noexcept
|
||||||
{
|
{
|
||||||
gameMemory = new MemoryPool(MemoryUnit::MebiByte, 512, 256);
|
gameMemory = new MemoryPool(MemoryUnit::MebiByte, 196, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_free(void* ptr)
|
void game_free(void* ptr) noexcept
|
||||||
{
|
{
|
||||||
gameMemory->free(ptr);
|
gameMemory->free(ptr);
|
||||||
}
|
}
|
|
@ -8,9 +8,8 @@ extern int malloc_free;
|
||||||
extern int malloc_used;
|
extern int malloc_used;
|
||||||
extern T5M::Memory::MemoryPool* gameMemory;
|
extern T5M::Memory::MemoryPool* gameMemory;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* game_malloc(size_t count= 1) {
|
[[nodiscard]] T* game_malloc(size_t count= 1) noexcept {
|
||||||
return gameMemory->malloc<T>(count);
|
return gameMemory->malloc<T>(count);
|
||||||
}
|
}
|
||||||
|
void init_game_malloc() noexcept;
|
||||||
void init_game_malloc();
|
void game_free(void* ptr) noexcept;
|
||||||
void game_free(void* ptr);
|
|
|
@ -18,6 +18,7 @@ namespace T5M::Memory {
|
||||||
static constexpr unsigned int MALLOC_MAGIC = 0xDEADBEEF;
|
static constexpr unsigned int MALLOC_MAGIC = 0xDEADBEEF;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
//Creates a Memory Pool with the specified memory and page size. The memory also contains the metadata and house keeping
|
||||||
MemoryPool(MemoryUnit unit, size_t amount, size_t pageSize) : pageSize(pageSize), size(static_cast<size_t>(unit)* amount), arena(new uint8_t[size]{0}) {
|
MemoryPool(MemoryUnit unit, size_t amount, size_t pageSize) : pageSize(pageSize), size(static_cast<size_t>(unit)* amount), arena(new uint8_t[size]{0}) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +35,8 @@ namespace T5M::Memory {
|
||||||
* Reserves Memory of type T with an additional count
|
* Reserves Memory of type T with an additional count
|
||||||
**/
|
**/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* malloc(size_t count = 1) {
|
[[nodiscard]] T* malloc(size_t count = 1) noexcept {
|
||||||
|
if (count < 1) return nullptr;
|
||||||
int pages;
|
int pages;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue