mirror of
https://github.com/pound-emu/pound.git
synced 2025-12-13 04:36:57 +00:00
memory: Move arena allocator into pound::memory namespace
The existing memory arena impelmentation is moved into the pound::memory namespace to align with the pound::aarch64 namespace. Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
parent
3d8a69dd8e
commit
556ace64e8
3 changed files with 10 additions and 8 deletions
|
|
@ -4,7 +4,8 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memory::arena_t memory::arena_init(size_t capacity)
|
namespace pound::memory {
|
||||||
|
arena_t arena_init(size_t capacity)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO(GloriousTaco:memory): Replace malloc with a windows memory mapping API.
|
// TODO(GloriousTaco:memory): Replace malloc with a windows memory mapping API.
|
||||||
|
|
@ -28,7 +29,7 @@ memory::arena_t memory::arena_init(size_t capacity)
|
||||||
}
|
}
|
||||||
// new more memsafe code (ownedbywuigi) (i give up on windows compatibility for now, will stick to the old unsafe code)
|
// new more memsafe code (ownedbywuigi) (i give up on windows compatibility for now, will stick to the old unsafe code)
|
||||||
|
|
||||||
const void* memory::arena_allocate(memory::arena_t* arena, const std::size_t size)
|
const void* arena_allocate(memory::arena_t* arena, const std::size_t size)
|
||||||
{
|
{
|
||||||
ASSERT(arena != nullptr);
|
ASSERT(arena != nullptr);
|
||||||
ASSERT(arena->size + size <= arena->capacity);
|
ASSERT(arena->size + size <= arena->capacity);
|
||||||
|
|
@ -36,14 +37,14 @@ const void* memory::arena_allocate(memory::arena_t* arena, const std::size_t siz
|
||||||
arena->size += size;
|
arena->size += size;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
void memory::arena_reset(memory::arena_t* arena)
|
void arena_reset(memory::arena_t* arena)
|
||||||
{
|
{
|
||||||
ASSERT(nullptr != arena);
|
ASSERT(nullptr != arena);
|
||||||
ASSERT(nullptr != arena->data);
|
ASSERT(nullptr != arena->data);
|
||||||
arena->size = 0;
|
arena->size = 0;
|
||||||
(void)std::memset(arena->data, POISON_PATTERN, arena->capacity);
|
(void)std::memset(arena->data, POISON_PATTERN, arena->capacity);
|
||||||
}
|
}
|
||||||
void memory::arena_free(memory::arena_t* arena)
|
void arena_free(memory::arena_t* arena)
|
||||||
{
|
{
|
||||||
ASSERT(arena != nullptr);
|
ASSERT(arena != nullptr);
|
||||||
arena->capacity = 0;
|
arena->capacity = 0;
|
||||||
|
|
@ -51,3 +52,4 @@ void memory::arena_free(memory::arena_t* arena)
|
||||||
// TODO(GloriousTaco:memory): Replace free with a memory safe alternative.
|
// TODO(GloriousTaco:memory): Replace free with a memory safe alternative.
|
||||||
free(arena->data);
|
free(arena->data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace memory
|
namespace pound::memory
|
||||||
{
|
{
|
||||||
#define POISON_PATTERN 0xAA
|
#define POISON_PATTERN 0xAA
|
||||||
|
|
||||||
|
|
@ -108,5 +108,5 @@ void arena_reset(arena_t* arena);
|
||||||
*/
|
*/
|
||||||
void arena_free(memory::arena_t* arena);
|
void arena_free(memory::arena_t* arena);
|
||||||
|
|
||||||
} // namespace memory
|
} // namespace pound::memory
|
||||||
#endif //POUND_ARENA_H
|
#endif //POUND_ARENA_H
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "arena.h"
|
#include "arena.h"
|
||||||
|
|
||||||
namespace memory
|
namespace pound::memory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@brief An STL-compatible allocator that uses a custom arena for memory management.
|
@brief An STL-compatible allocator that uses a custom arena for memory management.
|
||||||
|
|
@ -65,4 +65,4 @@ namespace memory
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // POUND_ARENA_ALLOCATOR_H
|
#endif // POUND_ARENA_ALLOCATOR_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue