Skip to content

Commit 192aa2b

Browse files
Add templated allocation function
1 parent fe28c9e commit 192aa2b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

MemoryPool.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ namespace CPPShift::Memory {
6363
*/
6464
void* allocate(size_t size);
6565

66+
// Templated allocation
67+
template<typename T>
68+
T* allocate(size_t instances);
69+
6670
/**
6771
* Re-allocates memory in a pool
6872
*
@@ -106,4 +110,10 @@ namespace CPPShift::Memory {
106110

107111
// Override new operators to create with memory pool
108112
extern void* operator new(size_t size, CPPShift::Memory::MemoryPool* mp);
109-
extern void* operator new[](size_t size, CPPShift::Memory::MemoryPool* mp);
113+
extern void* operator new[](size_t size, CPPShift::Memory::MemoryPool* mp);
114+
115+
116+
template<typename T>
117+
inline T* allocate(size_t instances) {
118+
return reinterpret_cast<T*>(this->allocate(instances * sizeof(T)));
119+
}

0 commit comments

Comments
 (0)