1
/*****************************************************************************
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/mem0dbg.h
21
The memory management: the debug code. This is not a compilation module,
22
but is included in mem0mem.* !
24
Created 6/9/1994 Heikki Tuuri
25
*******************************************************/
27
/* In the debug version each allocated field is surrounded with
28
check fields whose sizes are given below */
31
#define MEM_FIELD_HEADER_SIZE ut_calc_align(2 * sizeof(ulint),\
33
#define MEM_FIELD_TRAILER_SIZE sizeof(ulint)
35
#define MEM_FIELD_HEADER_SIZE 0
39
/* Space needed when allocating for a user a field of
40
length N. The space is allocated only in multiples of
41
UNIV_MEM_ALIGNMENT. In the debug version there are also
42
check fields at the both ends of the field. */
44
#define MEM_SPACE_NEEDED(N) ut_calc_align((N) + MEM_FIELD_HEADER_SIZE\
45
+ MEM_FIELD_TRAILER_SIZE, UNIV_MEM_ALIGNMENT)
47
#define MEM_SPACE_NEEDED(N) ut_calc_align((N), UNIV_MEM_ALIGNMENT)
50
#if defined UNIV_MEM_DEBUG || defined UNIV_DEBUG
51
/***************************************************************//**
52
Checks a memory heap for consistency and prints the contents if requested.
53
Outputs the sum of sizes of buffers given to the user (only in
54
the debug version), the physical size of the heap and the number of
55
blocks in the heap. In case of error returns 0 as sizes and number
59
mem_heap_validate_or_print(
60
/*=======================*/
61
mem_heap_t* heap, /*!< in: memory heap */
62
byte* top, /*!< in: calculate and validate only until
63
this top pointer in the heap is reached,
64
if this pointer is NULL, ignored */
65
ibool print, /*!< in: if TRUE, prints the contents
66
of the heap; works only in
68
ibool* error, /*!< out: TRUE if error */
69
ulint* us_size,/*!< out: allocated memory
70
(for the user) in the heap,
71
if a NULL pointer is passed as this
72
argument, it is ignored; in the
73
non-debug version this is always -1 */
74
ulint* ph_size,/*!< out: physical size of the heap,
75
if a NULL pointer is passed as this
76
argument, it is ignored */
77
ulint* n_blocks); /*!< out: number of blocks in the heap,
78
if a NULL pointer is passed as this
79
argument, it is ignored */
80
/**************************************************************//**
81
Validates the contents of a memory heap.
87
mem_heap_t* heap); /*!< in: memory heap */
88
#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
90
/**************************************************************//**
91
Checks that an object is a memory heap (or a block of it)
97
mem_heap_t* heap); /*!< in: memory heap */
98
#endif /* UNIV_DEBUG */
100
/*****************************************************************//**
101
TRUE if no memory is currently allocated.
102
@return TRUE if no heaps exist */
107
/*****************************************************************//**
108
Validates the dynamic memory
109
@return TRUE if error */
112
mem_validate_no_assert(void);
113
/*=========================*/
114
/************************************************************//**
115
Validates the dynamic memory
116
@return TRUE if ok */
121
#endif /* UNIV_MEM_DEBUG */
122
/************************************************************//**
123
Tries to find neigboring memory allocation blocks and dumps to stderr
124
the neighborhood of a given pointer. */
127
mem_analyze_corruption(
128
/*===================*/
129
void* ptr); /*!< in: pointer to place of possible corruption */
130
/*****************************************************************//**
131
Prints information of dynamic memory usage and currently allocated memory
132
heaps or buffers. Can only be used in the debug version. */
135
mem_print_info(void);
137
/*****************************************************************//**
138
Prints information of dynamic memory usage and currently allocated memory
139
heaps or buffers since the last ..._print_info or..._print_new_info. */
142
mem_print_new_info(void);
143
/*====================*/