Drizzled Public API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
mem0mem.h
Go to the documentation of this file.
1
/*****************************************************************************
2
3
Copyright (C) 1994, 2010, Innobase Oy. All Rights Reserved.
4
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.
8
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.
12
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., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
17
*****************************************************************************/
18
19
/**************************************************/
26
#pragma once
27
#ifndef mem0mem_h
28
#define mem0mem_h
29
30
#include "univ.i"
31
#include "
ut0mem.h
"
32
#include "
ut0byte.h
"
33
#include "
ut0rnd.h
"
34
#ifndef UNIV_HOTBACKUP
35
# include "
sync0sync.h
"
36
#endif
/* UNIV_HOTBACKUP */
37
#include "
ut0lst.h
"
38
#include "
mach0data.h
"
39
40
/* -------------------- MEMORY HEAPS ----------------------------- */
41
42
/* The info structure stored at the beginning of a heap block */
43
typedef
struct
mem_block_info_struct
mem_block_info_t
;
44
45
/* A block of a memory heap consists of the info structure
46
followed by an area of memory */
47
typedef
mem_block_info_t
mem_block_t
;
48
49
/* A memory heap is a nonempty linear list of memory blocks */
50
typedef
mem_block_t
mem_heap_t
;
51
52
/* Types of allocation for memory heaps: DYNAMIC means allocation from the
53
dynamic memory pool of the C compiler, BUFFER means allocation from the
54
buffer pool; the latter method is used for very big heaps */
55
56
#define MEM_HEAP_DYNAMIC 0
/* the most common type */
57
#define MEM_HEAP_BUFFER 1
58
#define MEM_HEAP_BTR_SEARCH 2
/* this flag can optionally be
59
ORed to MEM_HEAP_BUFFER, in which
60
case heap->free_block is used in
61
some cases for memory allocations,
62
and if NULL, the memory
63
allocation functions can return
64
NULL. */
65
66
/* The following start size is used for the first block in the memory heap if
67
the size is not specified, i.e., 0 is given as the parameter in the call of
68
create. The standard size is the maximum (payload) size of the blocks used for
69
allocations of small buffers. */
70
71
#define MEM_BLOCK_START_SIZE 64
72
#define MEM_BLOCK_STANDARD_SIZE \
73
(UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF)
74
75
/* If a memory heap is allowed to grow into the buffer pool, the following
76
is the maximum size for a single allocated buffer: */
77
#define MEM_MAX_ALLOC_IN_BUF (UNIV_PAGE_SIZE - 200)
78
79
/******************************************************************/
81
UNIV_INTERN
82
void
83
mem_init
(
84
/*=====*/
85
ulint size);
86
/******************************************************************/
88
UNIV_INTERN
89
void
90
mem_close
(
void
);
91
/*===========*/
92
93
/**************************************************************/
97
#define mem_heap_create(N) mem_heap_create_func(\
98
(N), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
99
/**************************************************************/
103
#define mem_heap_create_in_buffer(N) mem_heap_create_func(\
104
(N), MEM_HEAP_BUFFER, __FILE__, __LINE__)
105
/**************************************************************/
109
#define mem_heap_create_in_btr_search(N) mem_heap_create_func(\
110
(N), MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER,\
111
__FILE__, __LINE__)
112
113
/**************************************************************/
117
#define mem_heap_free(heap) mem_heap_free_func(\
118
(heap), __FILE__, __LINE__)
119
/*****************************************************************/
125
UNIV_INLINE
126
mem_heap_t
*
127
mem_heap_create_func
(
128
/*=================*/
129
ulint n,
133
ulint
type
,
134
const
char
* file_name,
135
ulint
line
);
136
/*****************************************************************/
140
UNIV_INLINE
141
void
142
mem_heap_free_func
(
143
/*===============*/
144
mem_heap_t
* heap,
145
const
char
* file_name,
146
ulint
line
);
147
/***************************************************************/
150
UNIV_INLINE
151
void
*
152
mem_heap_zalloc
(
153
/*============*/
154
mem_heap_t
* heap,
155
ulint n);
158
/***************************************************************/
162
UNIV_INLINE
163
void
*
164
mem_heap_alloc
(
165
/*===========*/
166
mem_heap_t
* heap,
167
ulint n);
170
/*****************************************************************/
173
UNIV_INLINE
174
byte*
175
mem_heap_get_heap_top
(
176
/*==================*/
177
mem_heap_t
* heap);
178
/*****************************************************************/
182
UNIV_INLINE
183
void
184
mem_heap_free_heap_top
(
185
/*===================*/
186
mem_heap_t
* heap,
187
byte* old_top);
188
/*****************************************************************/
190
UNIV_INLINE
191
void
192
mem_heap_empty
(
193
/*===========*/
194
mem_heap_t
* heap);
195
/*****************************************************************/
199
UNIV_INLINE
200
void
*
201
mem_heap_get_top
(
202
/*=============*/
203
mem_heap_t
* heap,
204
ulint n);
205
/*****************************************************************/
208
UNIV_INLINE
209
void
210
mem_heap_free_top
(
211
/*==============*/
212
mem_heap_t
* heap,
213
ulint n);
214
/*****************************************************************/
216
UNIV_INLINE
217
ulint
218
mem_heap_get_size
(
219
/*==============*/
220
mem_heap_t
* heap);
221
/**************************************************************/
225
#define mem_zalloc(N) memset(mem_alloc(N), 0, (N));
226
227
#define mem_alloc(N) mem_alloc_func((N), NULL, __FILE__, __LINE__)
228
#define mem_alloc2(N,S) mem_alloc_func((N), (S), __FILE__, __LINE__)
229
/***************************************************************/
235
UNIV_INLINE
236
void
*
237
mem_alloc_func
(
238
/*===========*/
239
ulint n,
240
ulint* size,
242
const
char
* file_name,
243
ulint
line
);
245
/**************************************************************/
249
#define mem_free(PTR) mem_free_func((PTR), __FILE__, __LINE__)
250
/***************************************************************/
254
UNIV_INLINE
255
void
256
mem_free_func
(
257
/*==========*/
258
void
* ptr,
259
const
char
* file_name,
260
ulint
line
);
262
/**********************************************************************/
265
UNIV_INLINE
266
char
*
267
mem_strdup
(
268
/*=======*/
269
const
char
* str);
270
/**********************************************************************/
273
UNIV_INLINE
274
char
*
275
mem_strdupl
(
276
/*========*/
277
const
char
* str,
278
ulint
len
);
280
/**********************************************************************/
283
UNIV_INTERN
284
char
*
285
mem_heap_strdup
(
286
/*============*/
287
mem_heap_t
* heap,
288
const
char
* str);
289
/**********************************************************************/
293
UNIV_INLINE
294
char
*
295
mem_heap_strdupl
(
296
/*=============*/
297
mem_heap_t
* heap,
298
const
char
* str,
299
ulint
len
);
301
/**********************************************************************/
304
UNIV_INTERN
305
char
*
306
mem_heap_strcat
(
307
/*============*/
308
mem_heap_t
* heap,
309
const
char
* s1,
310
const
char
* s2);
312
/**********************************************************************/
315
UNIV_INTERN
316
void
*
317
mem_heap_dup
(
318
/*=========*/
319
mem_heap_t
* heap,
320
const
void
* data,
321
ulint
len
);
323
/****************************************************************/
329
UNIV_INTERN
330
char
*
331
mem_heap_printf
(
332
/*============*/
333
mem_heap_t
* heap,
334
const
char
* format,
335
...) __attribute__ ((format (printf, 2, 3)));
336
337
#ifdef MEM_PERIODIC_CHECK
338
/******************************************************************/
341
UNIV_INTERN
342
void
343
mem_validate_all_blocks(
void
);
344
/*=========================*/
345
#endif
346
347
/*#######################################################################*/
348
349
/* The info header of a block in a memory heap */
350
351
struct
mem_block_info_struct
{
352
ulint magic_n;
/* magic number for debugging */
353
char
file_name[8];
/* file name where the mem heap was created */
354
ulint
line
;
355
UT_LIST_BASE_NODE_T(
mem_block_t
) base;
/* In the first block in the
356
the list this is the base node of the list of blocks;
357
in subsequent blocks this is undefined */
358
UT_LIST_NODE_T(
mem_block_t
) list;
/* This contains pointers to next
359
and prev in the list. The first block allocated
360
to the heap is also the first block in this list,
361
though it also contains the base node of the list. */
362
ulint
len
;
363
ulint
total_size
;
366
ulint
type
;
368
ulint
free
;
370
ulint
start
;
372
#ifndef UNIV_HOTBACKUP
373
void
* free_block;
374
/* if the MEM_HEAP_BTR_SEARCH bit is set in type,
375
and this is the heap root, this can contain an
376
allocated buffer frame, which can be appended as a
377
free block to the heap, if we need more space;
378
otherwise, this is NULL */
379
void
* buf_block;
380
/* if this block has been allocated from the buffer
381
pool, this contains the buf_block_t handle;
382
otherwise, this is NULL */
383
#endif
/* !UNIV_HOTBACKUP */
384
#ifdef MEM_PERIODIC_CHECK
385
UT_LIST_NODE_T(
mem_block_t
) mem_block_list;
386
/* List of all mem blocks allocated; protected
387
by the mem_comm_pool mutex */
388
#endif
389
};
390
391
#define MEM_BLOCK_MAGIC_N 764741555
392
#define MEM_FREED_BLOCK_MAGIC_N 547711122
393
394
/* Header size for a memory heap block */
395
#define MEM_BLOCK_HEADER_SIZE ut_calc_align(sizeof(mem_block_info_t),\
396
UNIV_MEM_ALIGNMENT)
397
#include "
mem0dbg.h
"
398
399
#ifndef UNIV_NONINL
400
#include "mem0mem.ic"
401
#endif
402
403
#endif
plugin
innobase
include
mem0mem.h
Generated on Sun Jun 3 2012 18:09:25 for drizzle by
1.8.1