MemoryTracking.h

00001 /* START_LICENSE_HEADER
00002 
00003 Copyright (C) 2000 Martin Piper, original design and program code
00004 Copyright (C) 2001 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 
00100 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsEnable(void);
00101 
00106 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsDisable(void);
00107 
00112 extern REPNETEXPORTAPI int ReplicaNet_MemoryTotalsState(void);
00113 
00119 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsQuery(int *blocks,int *allocated);
00120 
00127 extern REPNETEXPORTAPI void ReplicaNet_MemoryTotalsPeakQuery(int *blocks,int *allocated,int reset);
00128 
00129 
00130 // Internal function.
00134 extern REPNETEXPORTAPI int ReplicaNet_MemoryDumpAllocatedBlocks(void);
00135 // Internal function.
00136 extern REPNETEXPORTAPI void ReplicaNet_MemoryBreakOnAllocatedBlocks(const int numBlocks,const int *theBlocks);
00137 // Make sure the std calls are redirected to our own functions
00138 #if defined(_WIN32) || defined(_PS2)
00139 #ifndef _MEMORYTRACKING_CPP_
00140 #ifndef REPLICANET_NOMEMORYTRACKING
00141 #define malloc ReplicaNet_AllocateFunction
00142 #define realloc ReplicaNet_ReAllocateFunction
00143 #define calloc ReplicaNet_ClearAndAllocateFunc
00144 #define free ReplicaNet_FreeFunc
00145 #endif
00146 #endif
00147 #endif
00148 
00149 #ifdef __cplusplus
00150 }
00151 #endif
00152 
00153 #ifdef __cplusplus
00154 
00155 
00156 #if defined(_WIN32)
00157 #ifndef REPLICANET_NOMEMORYTRACKING
00158 // Claim the new and delete operators for our own purposes
00159 inline static void * __cdecl operator new(size_t size)
00160 {
00161     return ReplicaNet_AllocateFunction(size);
00162 }
00163 
00164 inline static void __cdecl operator delete(void *p)
00165 {
00166     ReplicaNet_FreeFunc(p);
00167 }
00168 #endif
00169 #endif
00170 
00171 
00172 #endif
00173 
00174 #endif

Generated on Sat Jun 28 22:02:16 2008 for ReplicaNet and RNLobby by  doxygen 1.5.3