the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 113 lines 2.2 kB view raw
1 2 3#pragma once 4#include "..\Minecraft.Client\Common\C4JMemoryPool.h" 5 6// Custom allocator, takes a C4JMemoryPool class, which can be one of a number of pool implementations. 7 8template <class T> 9class C4JPoolAllocator 10{ 11public: 12 typedef T value_type; 13 typedef size_t size_type; 14 typedef ptrdiff_t difference_type; 15 16 typedef T* pointer; 17 typedef const T* const_pointer; 18 19 typedef T& reference; 20 typedef const T& const_reference; 21 22 //! A struct to construct an allocator for a different type. 23 template<typename U> 24 struct rebind { typedef C4JPoolAllocator<U> other; }; 25 26 27 C4JMemoryPool* m_pPool; 28 bool m_selfAllocated; 29 30 C4JPoolAllocator( C4JMemoryPool* pool = new C4JMemoryPoolFixed(32, 4096 )) : m_pPool( pool ), m_selfAllocated(true) 31 { 32 printf("allocated mempool\n"); 33 } 34 35 template<typename U> 36 C4JPoolAllocator(C4JPoolAllocator<U> const& obj) : m_pPool( obj.m_pPool ), m_selfAllocated(false) // copy constructor 37 { 38 printf("C4JPoolAllocator constructed from 0x%08x\n", &obj); 39 assert(obj.m_pPool); 40 } 41private: 42 43public: 44 45 ~C4JPoolAllocator() 46 { 47 if(m_selfAllocated) 48 delete m_pPool; 49 } 50 51 pointer address( reference r ) const { return &r; } 52 const_pointer address( const_reference r ) const { return &r; } 53 54 pointer allocate( size_type n, const void* /*hint*/=0 ) 55 { 56 assert(m_pPool); 57 return (pointer)m_pPool->Alloc(n * sizeof(T)); 58 } 59 60 void deallocate( pointer p, size_type /*n*/ ) 61 { 62 assert(m_pPool); 63 m_pPool->Free(p); 64 } 65 66 void construct( pointer p, const T& val ) 67 { 68 new (p) T(val); 69 } 70 71 void destroy( pointer p ) 72 { 73 p->~T(); 74 } 75 76 size_type max_size() const 77 { 78 return ULONG_MAX / sizeof(T); 79 } 80 81}; 82 83 84template <class T> 85bool 86operator==( const C4JPoolAllocator<T>& left, const C4JPoolAllocator<T>& right ) 87{ 88 if (left.m_pPool == right.m_pPool) 89 { 90 return true; 91 } 92 return false; 93} 94 95template <class T> 96bool 97operator!=( const C4JPoolAllocator<T>& left, const C4JPoolAllocator<T>& right) 98{ 99 if (left.m_pPool != right.m_pPool) 100 { 101 return true; 102 } 103 return false; 104} 105 106 107 108 109 110 111 112 113