00001
00004 #ifndef FBXFILESDK_FBXFILESDK_MEMORY_H
00005 #define FBXFILESDK_FBXFILESDK_MEMORY_H
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <fbxfilesdk/components/kbaselib/karch/arch.h>
00046 #include <fbxfilesdk/components/kbaselib/karch/types.h>
00047
00048 #if defined(_DEBUG) && !defined(NDEBUG)
00049 #if defined(_MSC_VER) && !defined(_MFC_VER)
00050 #include <crtdbg.h>
00051 #endif
00052 #endif
00053
00054
00055 #include <stdlib.h>
00056 #include <string.h>
00057 #include <wchar.h>
00058
00059 #ifdef KARCH_ENV_WIN
00060 #include <mbstring.h>
00061 #endif
00062
00063 #ifndef KARCH_DEV_MACOSX
00064 #include <malloc.h>
00065 #endif
00066
00067 #include <new>
00068
00069 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00070
00071 #undef FbxSdkMsize
00072
00073 #ifndef KFBX_DLL
00074 #define KFBX_DLL KFBX_DLLIMPORT
00075 #endif
00076
00077
00078
00079 KFBX_DLL void* FbxSdkMalloc(size_t pBlockSize);
00080 KFBX_DLL void* FbxSdkCalloc(size_t pCount, size_t pBlockSize);
00081 KFBX_DLL void* FbxSdkRealloc(void* pData, size_t pBlockSize);
00082 KFBX_DLL void FbxSdkFree(void* pData);
00083 KFBX_DLL size_t FbxSdkMsize(void* pData);
00084 KFBX_DLL void* FbxSdkMalloc_Debug(size_t pBlockSize,int _BlockType,const char * _Filename,int _LineNumber);
00085 KFBX_DLL void* FbxSdkCalloc_Debug(size_t pCount, size_t pBlockSize,int _BlockType,const char * _Filename,int _LineNumber);
00086 KFBX_DLL void* FbxSdkRealloc_Debug(void* pData, size_t pBlockSize,int _BlockType,const char * _Filename,int _LineNumber);
00087 KFBX_DLL void FbxSdkFree_Debug(void* pData,int _BlockType);
00088 KFBX_DLL size_t FbxSdkMsize_Debug(void* pData,int _BlockType);
00089
00090 KFBX_DLL char* FbxStrDup(const char* pString);
00091 KFBX_DLL char* FbxStrDup_Debug(const char* pString, int _BlockType, const char* _Filename, int _LineNumber);
00092 KFBX_DLL wchar_t* FbxStrDupWC(const wchar_t* pString);
00093 KFBX_DLL wchar_t* FbxStrDupWC_Debug(const wchar_t* pString, int _BlockType, const char* _Filename, int _LineNumber);
00094 KFBX_DLL unsigned char* FbxStrDupMB(const unsigned char* pString);
00095 KFBX_DLL unsigned char* FbxStrDupMB_Debug(const unsigned char* pString, int _BlockType, const char* _Filename, int _LineNumber);
00096
00097
00098 KFBX_DLL void SetMallocHandler(void* (*pHandler)(size_t));
00099 KFBX_DLL void SetCallocHandler(void* (*pHandler)(size_t,size_t));
00100 KFBX_DLL void SetReallocHandler(void* (*pHandler)(void*,size_t));
00101 KFBX_DLL void SetFreeHandler(void (*pHandler)(void*));
00102 KFBX_DLL void SetMsizeHandler(size_t (*pHandler)(void*));
00103
00104 KFBX_DLL void SetMallocHandler_Debug(void* (*pHandler)(size_t,int,const char *,int));
00105 KFBX_DLL void SetCallocHandler_Debug(void* (*pHandler)(size_t,size_t,int,const char *,int));
00106 KFBX_DLL void SetReallocHandler_Debug(void* (*pHandler)(void*,size_t,int,const char *,int));
00107 KFBX_DLL void SetFreeHandler_Debug(void (*pHandler)(void*,int));
00108 KFBX_DLL void SetMsizeHandler_Debug(size_t (*pHandler)(void*,int));
00109
00110
00111 class KFBX_DLL KFbxPointerFreeGuard
00112 {
00113 public:
00114 KFbxPointerFreeGuard(void* p = NULL):mPtr(p)
00115 {
00116 }
00117 ~KFbxPointerFreeGuard()
00118 {
00119 FbxSdkFree(mPtr);
00120 mPtr = NULL;
00121 }
00122 void SetPointer (void* p)
00123 {
00124 mPtr = p;
00125 }
00126 private:
00127 void *mPtr;
00128 };
00129
00130
00131 #undef strdup
00132 #undef _strdup
00133 #undef _wcsdup
00134 #undef _mbsdup
00135
00136 #if defined(_DEBUG) && defined(KARCH_ENV_WIN)
00137 #define strdup(s) FBXFILESDK_NAMESPACE::FbxStrDup_Debug((s), _NORMAL_BLOCK, __FILE__, __LINE__)
00138 #define _strdup(s) FBXFILESDK_NAMESPACE::FbxStrDup_Debug((s), _NORMAL_BLOCK, __FILE__, __LINE__)
00139 #define _wcsdup(s) FBXFILESDK_NAMESPACE::FbxStrDupWC_Debug((s), _NORMAL_BLOCK, __FILE__, __LINE__)
00140 #define _mbsdup(s) FBXFILESDK_NAMESPACE::FbxStrDupMB_Debug((s), _NORMAL_BLOCK, __FILE__, __LINE__)
00141 #else
00142 #define strdup(s) FBXFILESDK_NAMESPACE::FbxStrDup((s))
00143 #define _strdup(s) FBXFILESDK_NAMESPACE::FbxStrDup((s))
00144 #define _wcsdup(s) FBXFILESDK_NAMESPACE::FbxStrDupWC((s))
00145 #define _mbsdup(s) FBXFILESDK_NAMESPACE::FbxStrDupMB((s))
00146 #endif
00147
00148 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00149
00150 #include <fbxfilesdk/fbxfilesdk_new.h>
00151
00152 #ifndef MB_FBXSDK
00153
00154
00155
00156
00157
00158 #undef FBXSDK_NEW_REDIRECTED
00159 #define FBXSDK_NEW_REDIRECTED
00160
00161 #undef MEMORY_DEBUG_FBXFILESDK_MEMORY
00162
00163 #ifndef DISABLE_FBXSDK_ALLOCATOR
00164 #if defined(_DEBUG) && !defined(NDEBUG)
00165 #define MEMORY_DEBUG_FBXFILESDK_MEMORY
00166 #endif
00167 #endif
00168
00169 #ifdef DISABLE_FBXSDK_ALLOCATOR
00170 #define FbxSdkMalloc(s) malloc(s)
00171 #define FbxSdkCalloc(c, s) calloc(c, s)
00172 #define FbxSdkRealloc(p, s) realloc(p, s)
00173 #define FbxSdkFree(p) free(p)
00174 #define FbxSdkMsize(p) _msize(p)
00175 #else
00176 #if ( defined(MEMORY_DEBUG) && defined(_DEBUG) && defined(KARCH_ENV_WIN32))
00177 #define FbxSdkMalloc(s) FbxSdkMalloc_Debug(s, _NORMAL_BLOCK, __FILE__, __LINE__)
00178 #define FbxSdkCalloc(c, s) FbxSdkCalloc_Debug(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
00179 #define FbxSdkRealloc(p, s) FbxSdkRealloc_Debug(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
00180 #define FbxSdkFree(p) FbxSdkFree_Debug(p, _NORMAL_BLOCK)
00181 #define FbxSdkMsize(p) FbxSdkMsize_Debug(p, _NORMAL_BLOCK)
00182 #endif
00183 #endif
00184
00185 #endif
00186
00187 #endif // FBXFILESDK_FBXFILESDK_MEMORY_H
00188
00189