mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
fixing memory leaks, begenning xmake support to build on windows
This commit is contained in:
47
src/core/memory.cpp
git.filemode.normal_file
47
src/core/memory.cpp
git.filemode.normal_file
@@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memory.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kbz_8 </var/spool/mail/kbz_8> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/07 16:32:01 by kbz_8 #+# #+# */
|
||||
/* Updated: 2023/12/07 16:43:56 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <core/memory.h>
|
||||
#include <core/errors.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void* MemManager::alloc(std::size_t size)
|
||||
{
|
||||
void* ptr = std::malloc(size);
|
||||
if(ptr != nullptr)
|
||||
_blocks.push_back(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MemManager::free(void* ptr)
|
||||
{
|
||||
auto it = std::find(_blocks.begin(), _blocks.end(), ptr);
|
||||
if(it == _blocks.end())
|
||||
{
|
||||
core::error::report(e_kind::error, "Memory Manager : trying to free a pointer not allocated by the memory manager");
|
||||
return;
|
||||
}
|
||||
std::free(*it);
|
||||
_blocks.erase(it);
|
||||
}
|
||||
|
||||
MemManager::~MemManager()
|
||||
{
|
||||
std::for_each(_blocks.begin(), _blocks.end(), [](void* ptr)
|
||||
{
|
||||
std::free(ptr);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user