75
57
is the maximum size for a single allocated buffer: */
76
58
#define MEM_MAX_ALLOC_IN_BUF (UNIV_PAGE_SIZE - 200)
78
/******************************************************************//**
60
/**********************************************************************
79
61
Initializes the memory system. */
84
ulint size); /*!< in: common pool size in bytes */
85
/******************************************************************//**
86
Closes the memory system. */
92
/**************************************************************//**
66
ulint size); /* in: common pool size in bytes */
67
/******************************************************************
93
68
Use this macro instead of the corresponding function! Macro for memory
96
71
#define mem_heap_create(N) mem_heap_create_func(\
97
72
(N), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
98
/**************************************************************//**
73
/******************************************************************
99
74
Use this macro instead of the corresponding function! Macro for memory
102
77
#define mem_heap_create_in_buffer(N) mem_heap_create_func(\
103
78
(N), MEM_HEAP_BUFFER, __FILE__, __LINE__)
104
/**************************************************************//**
79
/******************************************************************
105
80
Use this macro instead of the corresponding function! Macro for memory
109
84
(N), MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER,\
110
85
__FILE__, __LINE__)
112
/**************************************************************//**
87
/******************************************************************
113
88
Use this macro instead of the corresponding function! Macro for memory
116
91
#define mem_heap_free(heap) mem_heap_free_func(\
117
92
(heap), __FILE__, __LINE__)
118
/*****************************************************************//**
93
/*********************************************************************
119
94
NOTE: Use the corresponding macros instead of this function. Creates a
120
95
memory heap. For debugging purposes, takes also the file name and line as
122
@return own: memory heap, NULL if did not succeed (only possible for
123
MEM_HEAP_BTR_SEARCH type heaps) */
126
99
mem_heap_create_func(
127
100
/*=================*/
128
ulint n, /*!< in: desired start block size,
101
/* out, own: memory heap, NULL if
102
did not succeed (only possible for
103
MEM_HEAP_BTR_SEARCH type heaps)*/
104
ulint n, /* in: desired start block size,
129
105
this means that a single user buffer
130
106
of size n will fit in the block,
131
107
0 creates a default size block */
132
ulint type, /*!< in: heap type */
133
const char* file_name, /*!< in: file name where created */
134
ulint line); /*!< in: line where created */
135
/*****************************************************************//**
108
ulint type, /* in: heap type */
109
const char* file_name, /* in: file name where created */
110
ulint line); /* in: line where created */
111
/*********************************************************************
136
112
NOTE: Use the corresponding macro instead of this function. Frees the space
137
113
occupied by a memory heap. In the debug version erases the heap memory
141
117
mem_heap_free_func(
142
118
/*===============*/
143
mem_heap_t* heap, /*!< in, own: heap to be freed */
144
const char* file_name, /*!< in: file name where freed */
145
ulint line); /*!< in: line where freed */
146
/***************************************************************//**
147
Allocates and zero-fills n bytes of memory from a memory heap.
148
@return allocated, zero-filled storage */
119
mem_heap_t* heap, /* in, own: heap to be freed */
120
const char* file_name, /* in: file name where freed */
121
ulint line); /* in: line where freed */
122
/*******************************************************************
123
Allocates and zero-fills n bytes of memory from a memory heap. */
153
mem_heap_t* heap, /*!< in: memory heap */
154
ulint n); /*!< in: number of bytes; if the heap is allowed
128
/* out: allocated, zero-filled storage */
129
mem_heap_t* heap, /* in: memory heap */
130
ulint n); /* in: number of bytes; if the heap is allowed
155
131
to grow into the buffer pool, this must be
156
132
<= MEM_MAX_ALLOC_IN_BUF */
157
/***************************************************************//**
158
Allocates n bytes of memory from a memory heap.
159
@return allocated storage, NULL if did not succeed (only possible for
160
MEM_HEAP_BTR_SEARCH type heaps) */
133
/*******************************************************************
134
Allocates n bytes of memory from a memory heap. */
165
mem_heap_t* heap, /*!< in: memory heap */
166
ulint n); /*!< in: number of bytes; if the heap is allowed
139
/* out: allocated storage, NULL if did not
140
succeed (only possible for
141
MEM_HEAP_BTR_SEARCH type heaps) */
142
mem_heap_t* heap, /* in: memory heap */
143
ulint n); /* in: number of bytes; if the heap is allowed
167
144
to grow into the buffer pool, this must be
168
145
<= MEM_MAX_ALLOC_IN_BUF */
169
/*****************************************************************//**
170
Returns a pointer to the heap top.
171
@return pointer to the heap top */
146
/*********************************************************************
147
Returns a pointer to the heap top. */
174
150
mem_heap_get_heap_top(
175
151
/*==================*/
176
mem_heap_t* heap); /*!< in: memory heap */
177
/*****************************************************************//**
152
/* out: pointer to the heap top */
153
mem_heap_t* heap); /* in: memory heap */
154
/*********************************************************************
178
155
Frees the space in a memory heap exceeding the pointer given. The
179
156
pointer must have been acquired from mem_heap_get_heap_top. The first
180
157
memory block of the heap is not freed. */
183
160
mem_heap_free_heap_top(
184
161
/*===================*/
185
mem_heap_t* heap, /*!< in: heap from which to free */
186
byte* old_top);/*!< in: pointer to old top of heap */
187
/*****************************************************************//**
162
mem_heap_t* heap, /* in: heap from which to free */
163
byte* old_top);/* in: pointer to old top of heap */
164
/*********************************************************************
188
165
Empties a memory heap. The first memory block of the heap is not freed. */
193
mem_heap_t* heap); /*!< in: heap to empty */
194
/*****************************************************************//**
170
mem_heap_t* heap); /* in: heap to empty */
171
/*********************************************************************
195
172
Returns a pointer to the topmost element in a memory heap.
196
The size of the element must be given.
197
@return pointer to the topmost element */
173
The size of the element must be given. */
200
176
mem_heap_get_top(
201
177
/*=============*/
202
mem_heap_t* heap, /*!< in: memory heap */
203
ulint n); /*!< in: size of the topmost element */
204
/*****************************************************************//**
178
/* out: pointer to the topmost element */
179
mem_heap_t* heap, /* in: memory heap */
180
ulint n); /* in: size of the topmost element */
181
/*********************************************************************
205
182
Frees the topmost element in a memory heap.
206
183
The size of the element must be given. */
209
186
mem_heap_free_top(
210
187
/*==============*/
211
mem_heap_t* heap, /*!< in: memory heap */
212
ulint n); /*!< in: size of the topmost element */
213
/*****************************************************************//**
188
mem_heap_t* heap, /* in: memory heap */
189
ulint n); /* in: size of the topmost element */
190
/*********************************************************************
214
191
Returns the space in bytes occupied by a memory heap. */
217
194
mem_heap_get_size(
218
195
/*==============*/
219
mem_heap_t* heap); /*!< in: heap */
220
/**************************************************************//**
196
mem_heap_t* heap); /* in: heap */
197
/******************************************************************
221
198
Use this macro instead of the corresponding function!
222
199
Macro for memory buffer allocation */
226
203
#define mem_alloc(N) mem_alloc_func((N), NULL, __FILE__, __LINE__)
227
204
#define mem_alloc2(N,S) mem_alloc_func((N), (S), __FILE__, __LINE__)
228
/***************************************************************//**
205
/*******************************************************************
229
206
NOTE: Use the corresponding macro instead of this function.
230
207
Allocates a single buffer of memory from the dynamic memory of
231
208
the C compiler. Is like malloc of C. The buffer must be freed
233
@return own: free storage */
238
ulint n, /*!< in: requested size in bytes */
239
ulint* size, /*!< out: allocated size in bytes,
214
/* out, own: free storage */
215
ulint n, /* in: requested size in bytes */
216
ulint* size, /* out: allocated size in bytes,
241
const char* file_name, /*!< in: file name where created */
242
ulint line); /*!< in: line where created */
218
const char* file_name, /* in: file name where created */
219
ulint line); /* in: line where created */
244
/**************************************************************//**
221
/******************************************************************
245
222
Use this macro instead of the corresponding function!
246
223
Macro for memory buffer freeing */
248
225
#define mem_free(PTR) mem_free_func((PTR), __FILE__, __LINE__)
249
/***************************************************************//**
226
/*******************************************************************
250
227
NOTE: Use the corresponding macro instead of this function.
251
228
Frees a single buffer of storage from
252
229
the dynamic memory of C compiler. Similar to free of C. */
257
void* ptr, /*!< in, own: buffer to be freed */
258
const char* file_name, /*!< in: file name where created */
259
ulint line); /*!< in: line where created */
234
void* ptr, /* in, own: buffer to be freed */
235
const char* file_name, /* in: file name where created */
236
ulint line /* in: line where created */
261
/**********************************************************************//**
262
Duplicates a NUL-terminated string.
263
@return own: a copy of the string, must be deallocated with mem_free */
239
/**************************************************************************
240
Duplicates a NUL-terminated string. */
268
const char* str); /*!< in: string to be copied */
269
/**********************************************************************//**
270
Makes a NUL-terminated copy of a nonterminated string.
271
@return own: a copy of the string, must be deallocated with mem_free */
245
/* out, own: a copy of the string,
246
must be deallocated with mem_free */
247
const char* str); /* in: string to be copied */
248
/**************************************************************************
249
Makes a NUL-terminated copy of a nonterminated string. */
276
const char* str, /*!< in: string to be copied */
277
ulint len); /*!< in: length of str, in bytes */
254
/* out, own: a copy of the string,
255
must be deallocated with mem_free */
256
const char* str, /* in: string to be copied */
257
ulint len); /* in: length of str, in bytes */
279
/**********************************************************************//**
280
Duplicates a NUL-terminated string, allocated from a memory heap.
281
@return own: a copy of the string */
259
/**************************************************************************
260
Duplicates a NUL-terminated string, allocated from a memory heap. */
286
mem_heap_t* heap, /*!< in: memory heap where string is allocated */
287
const char* str); /*!< in: string to be copied */
288
/**********************************************************************//**
265
/* out, own: a copy of the string */
266
mem_heap_t* heap, /* in: memory heap where string is allocated */
267
const char* str); /* in: string to be copied */
268
/**************************************************************************
289
269
Makes a NUL-terminated copy of a nonterminated string,
290
allocated from a memory heap.
291
@return own: a copy of the string */
270
allocated from a memory heap. */
294
273
mem_heap_strdupl(
295
274
/*=============*/
296
mem_heap_t* heap, /*!< in: memory heap where string is allocated */
297
const char* str, /*!< in: string to be copied */
298
ulint len); /*!< in: length of str, in bytes */
275
/* out, own: a copy of the string */
276
mem_heap_t* heap, /* in: memory heap where string is allocated */
277
const char* str, /* in: string to be copied */
278
ulint len); /* in: length of str, in bytes */
300
/**********************************************************************//**
301
Concatenate two strings and return the result, using a memory heap.
302
@return own: the result */
280
/**************************************************************************
281
Concatenate two strings and return the result, using a memory heap. */
307
mem_heap_t* heap, /*!< in: memory heap where string is allocated */
308
const char* s1, /*!< in: string 1 */
309
const char* s2); /*!< in: string 2 */
286
/* out, own: the result */
287
mem_heap_t* heap, /* in: memory heap where string is allocated */
288
const char* s1, /* in: string 1 */
289
const char* s2); /* in: string 2 */
311
/**********************************************************************//**
312
Duplicate a block of data, allocated from a memory heap.
313
@return own: a copy of the data */
291
/**************************************************************************
292
Duplicate a block of data, allocated from a memory heap. */
318
mem_heap_t* heap, /*!< in: memory heap where copy is allocated */
319
const void* data, /*!< in: data to be copied */
320
ulint len); /*!< in: length of data, in bytes */
322
/****************************************************************//**
297
/* out, own: a copy of the data */
298
mem_heap_t* heap, /* in: memory heap where copy is allocated */
299
const void* data, /* in: data to be copied */
300
ulint len); /* in: length of data, in bytes */
302
/**************************************************************************
303
Concatenate two memory blocks and return the result, using a memory heap. */
308
/* out, own: the result */
309
mem_heap_t* heap, /* in: memory heap where result is allocated */
310
const void* b1, /* in: block 1 */
311
ulint len1, /* in: length of b1, in bytes */
312
const void* b2, /* in: block 2 */
313
ulint len2); /* in: length of b2, in bytes */
315
/********************************************************************
323
316
A simple (s)printf replacement that dynamically allocates the space for the
324
317
formatted string from the given heap. This supports a very limited set of
325
318
the printf syntax: types 's' and 'u' and length modifier 'l' (which is
326
required for the 'u' type).
327
@return heap-allocated formatted string */
319
required for the 'u' type). */
332
mem_heap_t* heap, /*!< in: memory heap */
333
const char* format, /*!< in: format string */
324
/* out: heap-allocated formatted string */
325
mem_heap_t* heap, /* in: memory heap */
326
const char* format, /* in: format string */
334
327
...) __attribute__ ((format (printf, 2, 3)));
336
329
#ifdef MEM_PERIODIC_CHECK
337
/******************************************************************//**
330
/**********************************************************************
338
331
Goes through the list of all allocated mem blocks, checks their magic
339
332
numbers, and reports possible corruption. */