50
50
allocations of small buffers. */
52
52
#define MEM_BLOCK_START_SIZE 64
53
#define MEM_BLOCK_STANDARD_SIZE \
54
(UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF)
53
#define MEM_BLOCK_STANDARD_SIZE 8000
56
55
/* If a memory heap is allowed to grow into the buffer pool, the following
57
56
is the maximum size for a single allocated buffer: */
71
70
#define mem_heap_create(N) mem_heap_create_func(\
72
(N), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
71
(N), NULL, MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
73
72
/******************************************************************
74
73
Use this macro instead of the corresponding function! Macro for memory
77
76
#define mem_heap_create_in_buffer(N) mem_heap_create_func(\
78
(N), MEM_HEAP_BUFFER, __FILE__, __LINE__)
77
(N), NULL, MEM_HEAP_BUFFER, __FILE__, __LINE__)
79
78
/******************************************************************
80
79
Use this macro instead of the corresponding function! Macro for memory
83
82
#define mem_heap_create_in_btr_search(N) mem_heap_create_func(\
84
(N), MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER,\
83
(N), NULL, MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER,\
85
84
__FILE__, __LINE__)
85
/******************************************************************
86
Use this macro instead of the corresponding function! Macro for fast
87
memory heap creation. An initial block of memory B is given by the
88
caller, N is its size, and this memory block is not freed by
89
mem_heap_free. See the parameter comment in mem_heap_create_func below. */
91
#define mem_heap_fast_create(N, B) mem_heap_create_func(\
92
(N), (B), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
87
94
/******************************************************************
88
95
Use this macro instead of the corresponding function! Macro for memory
104
111
ulint n, /* in: desired start block size,
105
112
this means that a single user buffer
106
113
of size n will fit in the block,
107
0 creates a default size block */
114
0 creates a default size block;
115
if init_block is not NULL, n tells
117
void* init_block, /* in: if very fast creation is
118
wanted, the caller can reserve some
119
memory from its stack, for example,
120
and pass it as the the initial block
121
to the heap: then no OS call of malloc
122
is needed at the creation. CAUTION:
123
the caller must make sure the initial
124
block is not unintentionally erased
125
(if allocated in the stack), before
126
the memory heap is explicitly freed. */
108
127
ulint type, /* in: heap type */
109
128
const char* file_name, /* in: file name where created */
110
129
ulint line); /* in: line where created */
120
139
const char* file_name, /* in: file name where freed */
121
140
ulint line); /* in: line where freed */
122
141
/*******************************************************************
123
Allocates and zero-fills n bytes of memory from a memory heap. */
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
131
to grow into the buffer pool, this must be
132
<= MEM_MAX_ALLOC_IN_BUF */
133
/*******************************************************************
134
142
Allocates n bytes of memory from a memory heap. */
198
206
Use this macro instead of the corresponding function!
199
207
Macro for memory buffer allocation */
201
#define mem_zalloc(N) memset(mem_alloc(N), 0, (N));
209
#define mem_alloc(N) mem_alloc_func((N), __FILE__, __LINE__)
210
/******************************************************************
211
Use this macro instead of the corresponding function!
212
Macro for memory buffer allocation */
203
#define mem_alloc(N) mem_alloc_func((N), NULL, __FILE__, __LINE__)
204
#define mem_alloc2(N,S) mem_alloc_func((N), (S), __FILE__, __LINE__)
214
#define mem_alloc_noninline(N) mem_alloc_func_noninline(\
215
(N), __FILE__, __LINE__)
205
216
/*******************************************************************
206
217
NOTE: Use the corresponding macro instead of this function.
207
218
Allocates a single buffer of memory from the dynamic memory of
214
225
/* out, own: free storage */
215
ulint n, /* in: requested size in bytes */
216
ulint* size, /* out: allocated size in bytes,
226
ulint n, /* in: desired number of bytes */
218
227
const char* file_name, /* in: file name where created */
219
ulint line); /* in: line where created */
228
ulint line /* in: line where created */
230
/*******************************************************************
231
NOTE: Use the corresponding macro instead of this function.
232
Allocates a single buffer of memory from the dynamic memory of
233
the C compiler. Is like malloc of C. The buffer must be freed
237
mem_alloc_func_noninline(
238
/*=====================*/
239
/* out, own: free storage */
240
ulint n, /* in: desired number of bytes */
241
const char* file_name, /* in: file name where created */
242
ulint line /* in: line where created */
221
244
/******************************************************************
222
245
Use this macro instead of the corresponding function!
223
246
Macro for memory buffer freeing */
330
353
/**********************************************************************
331
354
Goes through the list of all allocated mem blocks, checks their magic
332
355
numbers, and reports possible corruption. */
335
358
mem_validate_all_blocks(void);
336
359
/*=========================*/
354
377
ulint len; /* physical length of this block in bytes */
355
378
ulint type; /* type of heap: MEM_HEAP_DYNAMIC, or
356
379
MEM_HEAP_BUF possibly ORed to MEM_HEAP_BTR_SEARCH */
380
ibool init_block; /* TRUE if this is the first block used in fast
381
creation of a heap: the memory will be freed
382
by the creator, not by mem_heap_free */
357
383
ulint free; /* offset in bytes of the first free position for
358
384
user data in the block */
359
385
ulint start; /* the value of the struct field 'free' at the
360
386
creation of the block */
362
388
/* if the MEM_HEAP_BTR_SEARCH bit is set in type,
363
389
and this is the heap root, this can contain an
364
390
allocated buffer frame, which can be appended as a
365
391
free block to the heap, if we need more space;
366
392
otherwise, this is NULL */
368
/* if this block has been allocated from the buffer
369
pool, this contains the buf_block_t handle;
370
otherwise, this is NULL */
371
393
#ifdef MEM_PERIODIC_CHECK
372
394
UT_LIST_NODE_T(mem_block_t) mem_block_list;
373
395
/* List of all mem blocks allocated; protected