-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from 420verfl0w/indev
Merge from dev to master
- Loading branch information
Showing
12 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* memory.cpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/07 16:32:01 by kbz_8 #+# #+# */ | ||
/* Updated: 2023/12/08 12:56:14 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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* memory.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/07 16:31:51 by kbz_8 #+# #+# */ | ||
/* Updated: 2023/12/08 12:56:21 by kbz_8 ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef __MLX_MEMORY__ | ||
#define __MLX_MEMORY__ | ||
|
||
#include <utils/singleton.h> | ||
#include <list> | ||
|
||
namespace mlx | ||
{ | ||
class MemManager : public Singleton<MemManager> | ||
{ | ||
friend class Singleton<MemManager>; | ||
|
||
public: | ||
void* alloc(std::size_t size); | ||
void free(void* ptr); | ||
|
||
private: | ||
MemManager() = default; | ||
~MemManager(); | ||
|
||
private: | ||
std::list<void*> _blocks; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters