1 /******************************************************
2 The memory management: the debug code. This is not a compilation module,
3 but is included in mem0mem.* !
5 (c) 1994, 1995 Innobase Oy
7 Created 6/9/1994 Heikki Tuuri
8 *******************************************************/
10 /* In the debug version each allocated field is surrounded with
11 check fields whose sizes are given below */
14 #define MEM_FIELD_HEADER_SIZE ut_calc_align(2 * sizeof(ulint),\
16 #define MEM_FIELD_TRAILER_SIZE sizeof(ulint)
18 #define MEM_FIELD_HEADER_SIZE 0
22 /* Space needed when allocating for a user a field of
23 length N. The space is allocated only in multiples of
24 UNIV_MEM_ALIGNMENT. In the debug version there are also
25 check fields at the both ends of the field. */
27 #define MEM_SPACE_NEEDED(N) ut_calc_align((N) + MEM_FIELD_HEADER_SIZE\
28 + MEM_FIELD_TRAILER_SIZE, UNIV_MEM_ALIGNMENT)
30 #define MEM_SPACE_NEEDED(N) ut_calc_align((N), UNIV_MEM_ALIGNMENT)
33 #if defined UNIV_MEM_DEBUG || defined UNIV_DEBUG
34 /*******************************************************************
35 Checks a memory heap for consistency and prints the contents if requested.
36 Outputs the sum of sizes of buffers given to the user (only in
37 the debug version), the physical size of the heap and the number of
38 blocks in the heap. In case of error returns 0 as sizes and number
42 mem_heap_validate_or_print(
43 /*=======================*/
44 mem_heap_t
* heap
, /* in: memory heap */
45 byte
* top
, /* in: calculate and validate only until
46 this top pointer in the heap is reached,
47 if this pointer is NULL, ignored */
48 ibool print
, /* in: if TRUE, prints the contents
49 of the heap; works only in
51 ibool
* error
, /* out: TRUE if error */
52 ulint
* us_size
,/* out: allocated memory
53 (for the user) in the heap,
54 if a NULL pointer is passed as this
55 argument, it is ignored; in the
56 non-debug version this is always -1 */
57 ulint
* ph_size
,/* out: physical size of the heap,
58 if a NULL pointer is passed as this
59 argument, it is ignored */
60 ulint
* n_blocks
); /* out: number of blocks in the heap,
61 if a NULL pointer is passed as this
62 argument, it is ignored */
63 /******************************************************************
64 Validates the contents of a memory heap. */
70 mem_heap_t
* heap
); /* in: memory heap */
71 #endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
73 /******************************************************************
74 Checks that an object is a memory heap (or a block of it) */
80 mem_heap_t
* heap
); /* in: memory heap */
81 #endif /* UNIV_DEBUG */
83 /*********************************************************************
84 TRUE if no memory is currently allocated. */
89 /* out: TRUE if no heaps exist */
90 /*********************************************************************
91 Validates the dynamic memory */
94 mem_validate_no_assert(void);
95 /*=========================*/
96 /* out: TRUE if error */
97 /****************************************************************
98 Validates the dynamic memory */
103 /* out: TRUE if ok */
104 #endif /* UNIV_MEM_DEBUG */
105 /****************************************************************
106 Tries to find neigboring memory allocation blocks and dumps to stderr
107 the neighborhood of a given pointer. */
110 mem_analyze_corruption(
111 /*===================*/
112 void* ptr
); /* in: pointer to place of possible corruption */
113 /*********************************************************************
114 Prints information of dynamic memory usage and currently allocated memory
115 heaps or buffers. Can only be used in the debug version. */
118 mem_print_info(void);
120 /*********************************************************************
121 Prints information of dynamic memory usage and currently allocated memory
122 heaps or buffers since the last ..._print_info or..._print_new_info. */
125 mem_print_new_info(void);
126 /*====================*/