class Object abstract { friend class Application; static HANDLE processHeap; #ifdef _DEBUG static long allocCount; #endif public: static void * operator new(size_t size); static void operator delete(void *data); static void * realloc(void *old, size_t newsize); //static void * operator new[](size_t size); //static void operator delete[](void *data); }; HANDLE Object::processHeap; #ifdef _DEBUG long Object::allocCount; #endif __declspec(restrict) void * Object::operator new(size_t size) { assert(size); #ifdef _DEBUG InterlockedIncrement(&allocCount); #endif return HeapAlloc(processHeap, 0, size); } void Object::operator delete(void *data) { assert(data); #ifdef _DEBUG InterlockedDecrement(&allocCount); #endif HeapFree(processHeap, 0, data); } void * Object::realloc(void *old, size_t newsize) { return HeapReAlloc(processHeap, 0, old, newsize); } __declspec(restrict) void * __cdecl operator new(size_t size) { return Object::operator new(size); } void __cdecl operator delete(void *data) { Object::operator delete(data); } /* __declspec(restrict) void * Object::operator new[](size_t size) { assert(size); #ifdef _DEBUG InterlockedIncrement(&allocCount); #endif return HeapAlloc(processHeap, 0, size); } void Object::operator delete[](void *data) { assert(data); #ifdef _DEBUG InterlockedDecrement(&allocCount); #endif HeapFree(processHeap, 0, data); } */ template class Vector : public Object { T *Items; int Count; int Capacity; void Resize(); public: Vector(); Vector(int InitialCapacity); ~Vector(); T & operator [] (int idx); const T operator [] (int idx) const; }; template Vector::Vector() { Vector(4); } template Vector::Vector(int InitialCapacity) : Count(0), Capacity(InitialCapacity), Items(new int[InitialCapacity]) { } template Vector::~Vector() { delete[] Items; } template void Vector::Resize() { Items = (T *) Object::realloc(Items, Capacity * sizeof(T)); } template T & Vector::operator [] (int idx) { assert(idx >= 0); if (idx >= Count) { Count = idx + 1; if (idx >= Capacity) { Capacity = idx; Resize(); } } return Items[idx]; } template const T Vector::operator [] (int idx) const { assert(0 <= idx && idx <= Capacity); return Items[idx]; }