24 #ifndef __SystemAllocator__ 25 #define __SystemAllocator__ 27 #include "K2STLUtilities.h" 35 typedef size_t size_type;
36 typedef std::ptrdiff_t difference_type;
38 typedef const T* const_pointer;
40 typedef const T& const_reference;
44 pointer address(reference x)
const {
return &x;}
46 const_pointer address(const_reference x)
const {
return &x;}
49 pointer allocate(size_type n,
const void* hint = nil);
51 void deallocate(pointer p, size_type );
53 size_type max_size()
const {
return ULONG_MAX /
sizeof(T);}
56 void construct(pointer p,
const T& value) {
new(p) T(value);}
58 void destroy(pointer p) {p->~T();}
68 inline typename SystemAllocator<T>::pointer
71 size_t bytes = n*
sizeof(T);
73 #if defined(MACINTOSH) || defined(WASM) 75 void* ptr = malloc(bytes);
79 #elif defined(WINDOWS) 80 void* ptr = VirtualAlloc(nil, bytes, MEM_COMMIT, PAGE_READWRITE);
83 return static_cast<pointer
>(ptr);
90 #if defined(MACINTOSH) || defined(WASM) 94 #elif defined(WINDOWS) 95 BOOL success = VirtualFree(ptr, 0, MEM_RELEASE);
102 #endif // __SystemAllocator__