fbxfilesdk_memory.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_FBXFILESDK_MEMORY_H
00005 #define FBXFILESDK_FBXFILESDK_MEMORY_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2005 - 2006 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material
00013  (collectively the "Data") in these files contain unpublished information
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by
00015  Canada and United States of America federal copyright law and by international
00016  treaties.
00017 
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE,
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE.
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE.
00028 
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE.
00039 
00040 **************************************************************************************/
00041 //
00042 // This file must be included before any other file in the FBX SDK in order
00043 // to re-define the memory allocators
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 // Protect the standard C function declaration from macros defined below
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 // If we are compiling the FBX plugins or the public FBX SDK, we want to
00078 // use the FBX SDK internal memory allocator instead of the standard one.
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 // Functions to overwrite the default allocator functions
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     // In the FBX SDK, We redefine the m/c/realloc/free functions and the new/delete operators so the
00156     // FbxSdkManager can manage all the memory allocation/deallocation. 
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 /* MB_FBXSDK */
00186 
00187 #endif // FBXFILESDK_FBXFILESDK_MEMORY_H
00188 
00189