Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

MemoryTracking.h

00001 /* START_LICENSE_HEADER
00002 
00003 Copyright (C) 2000 Martin Piper, original design and program code
00004 Copyright (C) 2001-2005 Replica Software
00005 
00006 This program file is copyright (C) Replica Software and can only be used under license.
00007 For more information visit: http://www.replicanet.com/
00008 Or email: info@replicanet.com
00009 
00010 END_LICENSE_HEADER */
00011 #ifndef __MEMORYTRACKING_H__
00012 #define __MEMORYTRACKING_H__
00013 #include "RNPlatform/Inc/DLLExportAPI.h"
00014 
00015 // This file should be included first of all in all C/CPP files to ensure the memory hooks are used.
00016 
00017 // These standard includes are pulled in automatically here to enable a clean build without warnings to be done using MSVC.
00018 // Otherwise the MS compiler starts complaining about dll linkage with the allocation routines.
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <malloc.h>
00022 
00023 // Check for C++ being used
00024 #ifdef __cplusplus
00025 namespace RNReplicaNet
00026 {
00027 }
00028 
00029 extern "C"
00030 {
00031 #endif
00032 #include <stddef.h>
00033 typedef size_t tReplicaNet_Size;
00034 
00035 typedef void * tReplicaNet_AllocateFunc(tReplicaNet_Size);
00036 typedef void * tReplicaNet_ReAllocateFunc(void *, tReplicaNet_Size);
00037 typedef void * tReplicaNet_ClearAndAllocateFunc(tReplicaNet_Size, tReplicaNet_Size);
00038 typedef void tReplicaNet_FreeFunc(void *);
00039 
00044 extern REPNETEXPORTAPI void SetReplicaNetAllocateFunction(tReplicaNet_AllocateFunc *allocateFunction);
00049 extern REPNETEXPORTAPI void SetReplicaNetReAllocateFunction(tReplicaNet_ReAllocateFunc *reAllocateFunction);
00054 extern REPNETEXPORTAPI void SetReplicaNetClearAndAllocateFunction(tReplicaNet_ClearAndAllocateFunc *clearAndAllocateFunction);
00059 extern REPNETEXPORTAPI void SetReplicaNetFreeFunction(tReplicaNet_FreeFunc *freeFunction);
00060 
00066 extern REPNETEXPORTAPI void *ReplicaNet_AllocateFunction(tReplicaNet_Size size);
00067 
00074 extern REPNETEXPORTAPI void *ReplicaNet_ReAllocateFunction(void *memblock, tReplicaNet_Size size);
00075 
00082 extern REPNETEXPORTAPI void *ReplicaNet_ClearAndAllocateFunc(tReplicaNet_Size num, tReplicaNet_Size size);
00083 
00088 extern REPNETEXPORTAPI void ReplicaNet_FreeFunc(void *memblock);
00089 
00090 // Memory total generation
00091 
00096 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsEnable(void);
00097 
00102 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsDisable(void);
00103 
00108 extern REPNETEXPORTAPI int ReplicaNet_MemoryTotalsState(void);
00109 
00115 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsQuery(int *blocks,int *allocated);
00116 
00123 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsPeakQuery(int *blocks,int *allocated,int reset);
00124 
00125 
00126 // Internal function.
00127 extern REPNETEXPORTAPI void ReplicaNet_MemoryDumpAllocatedBlocks(void);
00128 // Internal function.
00129 extern REPNETEXPORTAPI void ReplicaNet_MemoryBreakOnAllocatedBlocks(const int numBlocks,const int *theBlocks);
00130 // Make sure the std calls are redirected to our own functions
00131 #if defined(_WIN32) || defined(_PS2)
00132 #ifndef _MEMORYTRACKING_CPP_
00133 #ifndef REPLICANET_NOMEMORYTRACKING
00134 #define malloc ReplicaNet_AllocateFunction
00135 #define realloc ReplicaNet_ReAllocateFunction
00136 #define calloc ReplicaNet_ClearAndAllocateFunc
00137 #define free ReplicaNet_FreeFunc
00138 #endif
00139 #endif
00140 #endif
00141 
00142 #ifdef __cplusplus
00143 };
00144 #endif
00145 
00146 #ifdef __cplusplus
00147 
00148 
00149 #if defined(_WIN32)
00150 #ifndef REPLICANET_NOMEMORYTRACKING
00151 // Claim the new and delete operators for our own purposes
00152 inline void * __cdecl operator new(size_t size)
00153 {
00154     return ReplicaNet_AllocateFunction(size);
00155 };
00156 
00157 inline void __cdecl operator delete(void *p)
00158 {
00159     ReplicaNet_FreeFunc(p);
00160 };
00161 #endif
00162 #endif
00163 
00164 
00165 #if defined(_PS2)
00166 #ifndef REPLICANET_NOMEMORYTRACKING
00167 // Claim the new and delete operators for our own purposes
00168 inline void * operator new(size_t size)
00169 {
00170     return ReplicaNet_AllocateFunction(size);
00171 };
00172 
00173 inline void operator delete(void *p)
00174 {
00175     ReplicaNet_FreeFunc(p);
00176 };
00177 #endif
00178 #endif
00179 
00180 
00181 #endif
00182 
00183 #endif

Generated on Sun Oct 30 01:12:31 2005 for Platform by  doxygen 1.4.1