All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
EegeoBaseNew.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include <new>
6 #include "Types.h"
7 #include "Allocator.h"
8 
9 #define Eegeo_BASE_NEW(allocator, type) new((void*)(allocator)->Alloc(__alignof(type), sizeof(type), __FILE__, __LINE__))type
10 
11 template <typename T>
12 void Eegeo_BASE_DELETE(Eegeo::Allocator* pAllocator, T* data)
13 {
14  if(data)
15  {
16  data->~T();
17  pAllocator->Free(data);
18  data = NULL;
19  }
20 }
21 
22 inline void* MemAllocArray(Eegeo::Allocator* pAllocator, size_t align, size_t typeSize, size_t num, const char* file, int line)
23 {
24 
25 
26  void* pData = pAllocator->Alloc(align, sizeof(size_t) + align + num * typeSize, file, line);
27  size_t* pDim = static_cast<size_t*>(pData);
28 
29  *pDim = num;
30  size_t dataOffset = (align > sizeof(size_t)) ? align : sizeof(size_t);
31  return static_cast<int*>(pData) + dataOffset;
32 }