00001 /****************************************************** 00002 The memory management: the debug code. This is not a compilation module, 00003 but is included in mem0mem.* ! 00004 00005 (c) 1994, 1995 Innobase Oy 00006 00007 Created 6/9/1994 Heikki Tuuri 00008 *******************************************************/ 00009 00010 /* In the debug version each allocated field is surrounded with 00011 check fields whose sizes are given below */ 00012 00013 #ifdef UNIV_MEM_DEBUG 00014 #define MEM_FIELD_HEADER_SIZE ut_calc_align(2 * sizeof(ulint),\ 00015 UNIV_MEM_ALIGNMENT) 00016 #define MEM_FIELD_TRAILER_SIZE sizeof(ulint) 00017 #else 00018 #define MEM_FIELD_HEADER_SIZE 0 00019 #endif 00020 00021 00022 /* Space needed when allocating for a user a field of 00023 length N. The space is allocated only in multiples of 00024 UNIV_MEM_ALIGNMENT. In the debug version there are also 00025 check fields at the both ends of the field. */ 00026 #ifdef UNIV_MEM_DEBUG 00027 #define MEM_SPACE_NEEDED(N) ut_calc_align((N) + MEM_FIELD_HEADER_SIZE\ 00028 + MEM_FIELD_TRAILER_SIZE, UNIV_MEM_ALIGNMENT) 00029 #else 00030 #define MEM_SPACE_NEEDED(N) ut_calc_align((N), UNIV_MEM_ALIGNMENT) 00031 #endif 00032 00033 /******************************************************************* 00034 Checks a memory heap for consistency and prints the contents if requested. 00035 Outputs the sum of sizes of buffers given to the user (only in 00036 the debug version), the physical size of the heap and the number of 00037 blocks in the heap. In case of error returns 0 as sizes and number 00038 of blocks. */ 00039 00040 void 00041 mem_heap_validate_or_print( 00042 /*=======================*/ 00043 mem_heap_t* heap, /* in: memory heap */ 00044 byte* top, /* in: calculate and validate only until 00045 this top pointer in the heap is reached, 00046 if this pointer is NULL, ignored */ 00047 ibool print, /* in: if TRUE, prints the contents 00048 of the heap; works only in 00049 the debug version */ 00050 ibool* error, /* out: TRUE if error */ 00051 ulint* us_size,/* out: allocated memory 00052 (for the user) in the heap, 00053 if a NULL pointer is passed as this 00054 argument, it is ignored; in the 00055 non-debug version this is always -1 */ 00056 ulint* ph_size,/* out: physical size of the heap, 00057 if a NULL pointer is passed as this 00058 argument, it is ignored */ 00059 ulint* n_blocks); /* out: number of blocks in the heap, 00060 if a NULL pointer is passed as this 00061 argument, it is ignored */ 00062 #ifdef UNIV_MEM_DEBUG 00063 /****************************************************************** 00064 Prints the contents of a memory heap. */ 00065 00066 void 00067 mem_heap_print( 00068 /*===========*/ 00069 mem_heap_t* heap); /* in: memory heap */ 00070 #endif /* UNIV_MEM_DEBUG */ 00071 /****************************************************************** 00072 Checks that an object is a memory heap (or a block of it) */ 00073 00074 ibool 00075 mem_heap_check( 00076 /*===========*/ 00077 /* out: TRUE if ok */ 00078 mem_heap_t* heap); /* in: memory heap */ 00079 /****************************************************************** 00080 Validates the contents of a memory heap. */ 00081 00082 ibool 00083 mem_heap_validate( 00084 /*==============*/ 00085 /* out: TRUE if ok */ 00086 mem_heap_t* heap); /* in: memory heap */ 00087 #ifdef UNIV_MEM_DEBUG 00088 /********************************************************************* 00089 TRUE if no memory is currently allocated. */ 00090 00091 ibool 00092 mem_all_freed(void); 00093 /*===============*/ 00094 /* out: TRUE if no heaps exist */ 00095 /********************************************************************* 00096 Validates the dynamic memory */ 00097 00098 ibool 00099 mem_validate_no_assert(void); 00100 /*=========================*/ 00101 /* out: TRUE if error */ 00102 /**************************************************************** 00103 Validates the dynamic memory */ 00104 00105 ibool 00106 mem_validate(void); 00107 /*===============*/ 00108 /* out: TRUE if ok */ 00109 #endif /* UNIV_MEM_DEBUG */ 00110 /**************************************************************** 00111 Tries to find neigboring memory allocation blocks and dumps to stderr 00112 the neighborhood of a given pointer. */ 00113 00114 void 00115 mem_analyze_corruption( 00116 /*===================*/ 00117 void* ptr); /* in: pointer to place of possible corruption */ 00118 /********************************************************************* 00119 Prints information of dynamic memory usage and currently allocated memory 00120 heaps or buffers. Can only be used in the debug version. */ 00121 00122 void 00123 mem_print_info(void); 00124 /*================*/ 00125 /********************************************************************* 00126 Prints information of dynamic memory usage and currently allocated memory 00127 heaps or buffers since the last ..._print_info or..._print_new_info. */ 00128 00129 void 00130 mem_print_new_info(void); 00131 /*====================*/
1.4.7

