Lugdunum  0.1.0
Basic.cpp
Go to the documentation of this file.
2 #include <malloc.h>
3 #include <lug/System/Debug.hpp>
4 
5 namespace lug {
6 namespace System {
7 namespace Memory {
8 namespace Allocator {
9 
10 void* Basic::allocate(size_t size, size_t alignment, size_t offset) const {
11 #if defined(LUG_SYSTEM_LINUX)
12  return aligned_alloc(alignment + offset, size);
13 #elif defined(LUG_SYSTEM_ANDROID)
14  void* ret = nullptr;
15 
16  if (!posix_memalign(&ret, alignment + offset, size)) {
17  return ret;
18  }
19 
20  return nullptr;
21 #elif defined(LUG_SYSTEM_WINDOWS)
22  return _aligned_malloc(alignment + offset, size);
23 #endif
24 }
25 
26 void Basic::free(void* ptr) const {
27  std::free(ptr);
28 }
29 
30 void Basic::reset() const {
31  LUG_ASSERT(false, "Basic allocator doesn't implement reset method");
32 }
33 
34 size_t Basic::getSize(void* ptr) const {
35 #if defined(LUG_SYSTEM_WINDOWS)
36  return _msize(ptr);
37 #else
38  return malloc_usable_size(ptr);
39 #endif
40 }
41 
42 } // Allocator
43 } // Memory
44 } // System
45 } // lug
#define LUG_ASSERT(assertion, message)
Definition: Debug.hpp:38
size_t getSize(void *ptr) const
Definition: Basic.cpp:34
void * allocate(size_t size, size_t alignment, size_t offset) const
Definition: Basic.cpp:10
void free(void *ptr) const
Definition: Basic.cpp:26