/////////////////////////////////////////////////////////////////////// // SpeedTreeAllocator.h // // *** INTERACTIVE DATA VISUALIZATION (IDV) CONFIDENTIAL AND PROPRIETARY INFORMATION *** // // This software is supplied under the terms of a license agreement or // nondisclosure agreement with Interactive Data Visualization, Inc. and // may not be copied, disclosed, or exploited except in accordance with // the terms of that agreement. // // Copyright (c) 2003-2007 IDV, Inc. // All rights reserved in all media. // // IDV, Inc. // http://www.idvinc.com // // *** Release version 4.1 *** #pragma once #ifdef WIN32 #pragma warning (disable : 4786) #endif #include #include #include #include #ifdef TRACK_ALLOC_STATS #include #endif // storage-class specification #if (defined(WIN32) || defined(_XBOX)) && defined(SPEEDTREE_DLL_EXPORTS) #define ST_STORAGE_CLASS __declspec(dllexport) #else #define ST_STORAGE_CLASS #endif /////////////////////////////////////////////////////////////////////// // class CSpeedTreeAllocator class ST_STORAGE_CLASS CSpeedTreeAllocator { public: virtual ~CSpeedTreeAllocator( ) { } virtual void* Alloc(size_t BlockSize, size_t Alignment = 16) = 0; virtual void Free(void* pBlock) = 0; #ifdef TRACK_ALLOC_STATS static void TrackAlloc(const char* pDescription, void* pBlock, size_t sAmount); static void TrackFree(const char* pDescription, void* pBlock, size_t sAmount); static bool Report(const char* pFilename); struct ST_STORAGE_CLASS SAllocStats { SAllocStats( ) : m_siNumAllocates(0), m_siAmountAllocated(0), m_siNumFrees(0), m_siAmountFreed(0) { } bool operator<(const SAllocStats& sRight) { return sRight.m_siNumAllocates < m_siNumAllocates; } SAllocStats& operator+=(const SAllocStats& sRight) { m_siNumAllocates += sRight.m_siNumAllocates; m_siAmountAllocated += sRight.m_siAmountAllocated; m_siNumFrees += sRight.m_siNumFrees; m_siAmountFreed += sRight.m_siAmountFreed; return *this; } std::string m_strDesc; size_t m_siNumAllocates; size_t m_siAmountAllocated; size_t m_siNumFrees; size_t m_siAmountFreed; }; struct ST_STORAGE_CLASS SLeakStats { SLeakStats( ) : m_nCount(0), m_nAmount(0) { } bool operator<(const SLeakStats& cRight) { return m_nAmount > cRight.m_nAmount; // backwards on purpose } std::string m_strDesc; int m_nCount; int m_nAmount; }; typedef std::map stats_map; typedef std::map leak_map; #endif // TRACK_ALLOC_STATS };