maxheapdirect.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        MAXHeapDirect.h
00012 // DESCRIPTION: Access to the memory routines used by Max. (Can be called 
00013 //              from plug-ins compiled with different memory handling.)
00014 // AUTHOR:      Cleve Ard & Michaelson Britt
00015 // HISTORY:     Created, Oct. 2003
00016 //              Renamed from max_memdirect.h to maxheapdirect.h, April 2006
00017 //**************************************************************************/
00018 
00019 #pragma once
00020 #include <WTypes.h>
00021 #include <crtdbg.h>
00022 #include <malloc.h>
00023 #include <new.h>
00024 
00025 #include "utilexp.h"
00026 
00027 #undef MAXMEM_EXTERN_C
00028 #ifdef  __cplusplus
00029 #   define MAXMEM_EXTERN_C  extern "C"
00030 #else
00031 #   define MAXMEM_EXTERN_C
00032 #endif
00033 
00034 // NOTE: For efficiency, most functions are declared as pointers which
00035 // route into the corresponding function.  This avoids passing through
00036 // a "wrapper" layer.
00037 //
00038 // New and Delete were implemented with wrappers, so that the original
00039 // MAX_Mem.h could use function overloads with them, since this is not
00040 // possible with the preprocessor.
00041 //   int* x = new;
00042 // There's no way to define 'new' as a preprocessor macro such that
00043 // 'new int' is translated to 'MAX_new( sizeof(int) )'
00044 
00045 UtilExport void *__cdecl MAX_new(size_t size);
00046 
00047 UtilExport void *__cdecl MAX_new_array(size_t size);
00048 
00049 // Disabled: Placement forms not supported
00050 //UtilExport void *__cdecl MAX_new_placement(size_t size, void *_P);
00051 
00052 UtilExport void __cdecl MAX_delete(void* mem);
00053 
00054 UtilExport void __cdecl MAX_delete_array(void* mem);
00055 
00056 // Disabled: Placement forms not supported
00057 //UtilExport void __cdecl MAX_delete_placement(void *memblock, void *_P);
00058 
00059 //Allocate block of memory from heap 
00060 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_malloc)(size_t size);
00061 
00062 //Allocate storage for array, initializing every byte in allocated block to 0 
00063 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_calloc)(size_t num, size_t size);
00064 
00065 //Reallocate block to new size 
00066 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_realloc)(void *memblock, size_t size);
00067 
00068 //Expand or shrink block of memory without moving it 
00069 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_expand)(void * memblock, size_t size);
00070 
00071 //Free allocated block 
00072 MAXMEM_EXTERN_C UtilExport void (__cdecl *MAX_free)(void * memblock);
00073 
00074 //Return size of allocated block 
00075 MAXMEM_EXTERN_C UtilExport size_t   (__cdecl *MAX_msize)(void *memblock);
00076 
00077 // Set hook function
00078 // Disabled: because HEAPHOOK does not seem to be enabled in practice
00079 //UtilExport _HEAPHOOK (__cdecl *MAX_setheaphook)(_HEAPHOOK);
00080 
00081 //Add memory to heap 
00082 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_heapadd)(void * memblock, size_t size);
00083 
00084 //Check heap for consistency 
00085 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_heapchk)(void);
00086 
00087 //Release unused memory in heap 
00088 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_heapmin)(void);
00089 
00090 //Fill free heap entries with specified value 
00091 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_heapset)(unsigned int fill);
00092 
00093 //Return information about each entry in heap 
00094 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_heapwalk)(_HEAPINFO *entryinfo);
00095 
00096 //Return address of current new handler routine as set by _set_new_handler 
00097 MAXMEM_EXTERN_C UtilExport _PNH (__cdecl *MAX_query_new_handler)( void );
00098 
00099 //Enable error-handling mechanism when new operator fails (to allocate memory) and enable compilation of Standard Template Libraries (STL) 
00100 MAXMEM_EXTERN_C UtilExport _PNH (__cdecl *MAX_set_new_handler)( _PNH pNewHandler );
00101 
00102 //Return integer indicating new handler mode set by _set_new_mode for malloc 
00103 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_query_new_mode)( void );
00104 
00105 //Set new handler mode for malloc 
00106 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_set_new_mode)( int newhandlermode );
00107 
00108 //Get/Set the upper limit for the size of a memory allocation that will be supported by the small-block heap 
00109 MAXMEM_EXTERN_C UtilExport size_t   (__cdecl *MAX_get_sbh_threshold)(void);
00110 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_set_sbh_threshold)(size_t size);
00111 
00112 
00113 //-----------------------------------------------------------------------------
00114 // The following debug functions are available only in a Sparks debug build
00115 
00116 #ifdef _DEBUG
00117 #ifndef IS_HYBRID
00118 
00119 //Debug version of calloc; only available in the debug versions of the run-time libraries 
00120 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_calloc_dbg)(size_t num, size_t size, int blockType, const char * filename, int lineNumber);
00121 
00122 //Debug version of _expand; only available in the debug versions of the run-time libraries 
00123 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_expand_dbg)(void * userData, size_t newSize, int blockType, const char * filename, int lineNumber);
00124 
00125 //Debug version of malloc; only available in the debug versions of the run-time libraries 
00126 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_malloc_dbg)(size_t size,int blockType,const char *filename,int lineNumber);
00127 
00128 //Debug version of free; only available in the debug versions of the run-time libraries 
00129 MAXMEM_EXTERN_C UtilExport void (__cdecl *MAX_free_dbg)(void * userData, int blockType);
00130 
00131 //Debug version of _msize; only available in the debug versions of the run-time libraries 
00132 MAXMEM_EXTERN_C UtilExport size_t   (__cdecl *MAX_msize_dbg)(void *userData, int blockType);
00133 
00134 //Debug version of realloc; only available in the debug versions of the run-time libraries 
00135 MAXMEM_EXTERN_C UtilExport void *   (__cdecl *MAX_realloc_dbg)(void *userData, size_t newSize, int blockType, const char *filename, int lineNumber);
00136 
00137 MAXMEM_EXTERN_C UtilExport extern long& MAX_crtAssertBusy;
00138 
00139 //Install a client-defined reporting function by hooking it into the C run-time debug reporting process
00140 MAXMEM_EXTERN_C UtilExport _CRT_REPORT_HOOK (__cdecl *MAX_CrtSetReportHook)(_CRT_REPORT_HOOK reportHook);
00141 
00142 //Install a client-defined reporting function by hooking it into the C run-time debug reporting process
00143 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtSetReportMode)(int reportType,int reportMode);
00144 
00145 //Identify the file or stream to be used as a destination for a specific report type by _CrtDbgReport
00146 MAXMEM_EXTERN_C UtilExport _HFILE   (__cdecl *MAX_CrtSetReportFile)(int reportType,_HFILE reportFile);
00147 
00148 //Generate a debug report with a user message and send the report to three possible destinations
00149 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtDbgReport)(int,const char *,int,const char *,const char *,...);
00150 
00151 MAXMEM_EXTERN_C UtilExport void __cdecl MAX_CrtDbgBreak(void);
00152 
00153 MAXMEM_EXTERN_C UtilExport extern long& MAX_crtBreakAlloc;      /* Break on this allocation */
00154 
00155 //Set a breakpoint on a specified object allocation order number
00156 MAXMEM_EXTERN_C UtilExport long (__cdecl *MAX_CrtSetBreakAlloc)(long lBreakAlloc);
00157 
00158 //Install a client-defined allocation function by hooking it into the C run-time debug memory allocation process
00159 MAXMEM_EXTERN_C UtilExport _CRT_ALLOC_HOOK  (__cdecl *MAX_CrtSetAllocHook)(_CRT_ALLOC_HOOK allocHook);
00160 
00161 MAXMEM_EXTERN_C UtilExport extern int& MAX_crtDbgFlag;
00162 
00163 //Confirm the integrity of the memory blocks allocated on the debug heap
00164 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtCheckMemory)(void);
00165 
00166 //Retrieve or modify the state of the _crtDbgFlag flag to control the allocation behavior of the debug heap manager
00167 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtSetDbgFlag)(int newFlag);
00168 
00169 //Call an application-supplied function for all _CLIENT_BLOCK types on the heap
00170 MAXMEM_EXTERN_C UtilExport void (__cdecl *MAX_CrtDoForAllClientObjects)(void (*pfn)(void *, void *),void *context);
00171 
00172 //Verify that a specified memory range is valid for reading and writing
00173 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtIsValidPointer)(const void *address,unsigned int size,int access);
00174 
00175 //Verify that a specified pointer is in the local heap
00176 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtIsValidHeapPointer)(const void *userData);
00177 
00178 //Verify that a specified memory block is located within the local heap and that it has a valid debug heap block type identifier
00179 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtIsMemoryBlock)(const void *userData,unsigned int size,long *requestNumber,char **filename,int *linenumber);
00180 
00181 //Install an application-defined function that is called every time a debug dump function is called to dump _CLIENT_BLOCK type memory blocks
00182 MAXMEM_EXTERN_C UtilExport _CRT_DUMP_CLIENT (__cdecl *MAX_CrtSetDumpClient)(_CRT_DUMP_CLIENT dumpClient);
00183 
00184 //Obtain the current state of the debug heap and store it in an application-supplied _CrtMemState structure
00185 MAXMEM_EXTERN_C UtilExport void (__cdecl *MAX_CrtMemCheckpoint)(_CrtMemState *state);
00186 
00187 //Compare two memory states for significant differences and return the results
00188 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtMemDifference)(_CrtMemState *stateDiff,const _CrtMemState *oldState,const _CrtMemState *newState);
00189 
00190 //Dump information about objects on the heap since a specified checkpoint was taken or from the start of program execution
00191 MAXMEM_EXTERN_C UtilExport void (__cdecl *MAX_CrtMemDumpAllObjectsSince)(const _CrtMemState *state);
00192 
00193 //Dump the debug header information for a specified memory state in a user-readable form
00194 MAXMEM_EXTERN_C UtilExport void (__cdecl *MAX_CrtMemDumpStatistics)(const _CrtMemState *state);
00195 
00196 //Dump all of the memory blocks on the debug heap when a significant memory leak has occurred
00197 MAXMEM_EXTERN_C UtilExport int  (__cdecl *MAX_CrtDumpMemoryLeaks)(void);
00198 
00199 #endif //IS_HYBRID
00200 #endif //_DEBUG
00201 
00202