drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
mem0mem.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (C) 1994, 2010, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/**************************************************/
25
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 */
43typedef struct mem_block_info_struct mem_block_info_t;
44
45/* A block of a memory heap consists of the info structure
46followed by an area of memory */
47typedef mem_block_info_t mem_block_t;
48
49/* A memory heap is a nonempty linear list of memory blocks */
50typedef mem_block_t mem_heap_t;
51
52/* Types of allocation for memory heaps: DYNAMIC means allocation from the
53dynamic memory pool of the C compiler, BUFFER means allocation from the
54buffer 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
67the size is not specified, i.e., 0 is given as the parameter in the call of
68create. The standard size is the maximum (payload) size of the blocks used for
69allocations 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
76is the maximum size for a single allocated buffer: */
77#define MEM_MAX_ALLOC_IN_BUF (UNIV_PAGE_SIZE - 200)
78
79/******************************************************************/
81UNIV_INTERN
82void
84/*=====*/
85 ulint size);
86/******************************************************************/
88UNIV_INTERN
89void
90mem_close(void);
91/*===========*/
92
93/**************************************************************/
96
97#define mem_heap_create(N) mem_heap_create_func(\
98 (N), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
99/**************************************************************/
102
103#define mem_heap_create_in_buffer(N) mem_heap_create_func(\
104 (N), MEM_HEAP_BUFFER, __FILE__, __LINE__)
105/**************************************************************/
106
108
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/**************************************************************/
116
117#define mem_heap_free(heap) mem_heap_free_func(\
118 (heap), __FILE__, __LINE__)
119/*****************************************************************/
125UNIV_INLINE
126mem_heap_t*
128/*=================*/
129 ulint n,
133 ulint type,
134 const char* file_name,
135 ulint line);
136/*****************************************************************/
140UNIV_INLINE
141void
143/*===============*/
144 mem_heap_t* heap,
145 const char* file_name,
146 ulint line);
147/***************************************************************/
150UNIV_INLINE
151void*
153/*============*/
154 mem_heap_t* heap,
155 ulint n);
158/***************************************************************/
162UNIV_INLINE
163void*
165/*===========*/
166 mem_heap_t* heap,
167 ulint n);
170/*****************************************************************/
173UNIV_INLINE
174byte*
176/*==================*/
177 mem_heap_t* heap);
178/*****************************************************************/
182UNIV_INLINE
183void
185/*===================*/
186 mem_heap_t* heap,
187 byte* old_top);
188/*****************************************************************/
190UNIV_INLINE
191void
193/*===========*/
194 mem_heap_t* heap);
195/*****************************************************************/
199UNIV_INLINE
200void*
202/*=============*/
203 mem_heap_t* heap,
204 ulint n);
205/*****************************************************************/
208UNIV_INLINE
209void
211/*==============*/
212 mem_heap_t* heap,
213 ulint n);
214/*****************************************************************/
216UNIV_INLINE
217ulint
219/*==============*/
220 mem_heap_t* heap);
221/**************************************************************/
224
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/***************************************************************/
235UNIV_INLINE
236void *
238/*===========*/
239 ulint n,
240 ulint* size,
242 const char* file_name,
243 ulint line);
244
245/**************************************************************/
248
249#define mem_free(PTR) mem_free_func((PTR), __FILE__, __LINE__)
250/***************************************************************/
254UNIV_INLINE
255void
257/*==========*/
258 void* ptr,
259 const char* file_name,
260 ulint line);
262/**********************************************************************/
265UNIV_INLINE
266char*
268/*=======*/
269 const char* str);
270/**********************************************************************/
273UNIV_INLINE
274char*
276/*========*/
277 const char* str,
278 ulint len);
279
280/**********************************************************************/
283UNIV_INTERN
284char*
286/*============*/
287 mem_heap_t* heap,
288 const char* str);
289/**********************************************************************/
293UNIV_INLINE
294char*
296/*=============*/
297 mem_heap_t* heap,
298 const char* str,
299 ulint len);
300
301/**********************************************************************/
304UNIV_INTERN
305char*
307/*============*/
308 mem_heap_t* heap,
309 const char* s1,
310 const char* s2);
311
312/**********************************************************************/
315UNIV_INTERN
316void*
318/*=========*/
319 mem_heap_t* heap,
320 const void* data,
321 ulint len);
322
323/****************************************************************/
329UNIV_INTERN
330char*
332/*============*/
333 mem_heap_t* heap,
334 const char* format,
335 ...) __attribute__ ((format (printf, 2, 3)));
336
337#ifdef MEM_PERIODIC_CHECK
338/******************************************************************/
341UNIV_INTERN
342void
343mem_validate_all_blocks(void);
344/*=========================*/
345#endif
346
347/*#######################################################################*/
349/* The info header of a block in a memory heap */
350
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
UNIV_INTERN char * mem_heap_strdup(mem_heap_t *heap, const char *str)
Definition mem0mem.cc:104
UNIV_INLINE mem_heap_t * mem_heap_create_func(ulint n, ulint type, const char *file_name, ulint line)
UNIV_INLINE void mem_heap_free_top(mem_heap_t *heap, ulint n)
UNIV_INLINE void mem_heap_free_func(mem_heap_t *heap, const char *file_name, ulint line)
UNIV_INTERN void mem_init(ulint size)
Definition mem0dbg.cc:149
UNIV_INTERN void * mem_heap_dup(mem_heap_t *heap, const void *data, ulint len)
Definition mem0mem.cc:117
UNIV_INLINE ulint mem_heap_get_size(mem_heap_t *heap)
UNIV_INLINE void * mem_heap_get_top(mem_heap_t *heap, ulint n)
UNIV_INTERN char * mem_heap_strcat(mem_heap_t *heap, const char *s1, const char *s2)
Definition mem0mem.cc:131
UNIV_INLINE char * mem_heap_strdupl(mem_heap_t *heap, const char *str, ulint len)
UNIV_INLINE char * mem_strdup(const char *str)
UNIV_INLINE byte * mem_heap_get_heap_top(mem_heap_t *heap)
UNIV_INLINE void mem_heap_free_heap_top(mem_heap_t *heap, byte *old_top)
UNIV_INLINE void mem_free_func(void *ptr, const char *file_name, ulint line)
UNIV_INLINE void mem_heap_empty(mem_heap_t *heap)
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
UNIV_INTERN char * mem_heap_printf(mem_heap_t *heap, const char *format,...) __attribute__((format(printf
UNIV_INLINE char * mem_strdupl(const char *str, ulint len)
UNIV_INTERN void mem_close(void)
Definition mem0dbg.cc:186
UNIV_INLINE void * mem_heap_zalloc(mem_heap_t *heap, ulint n)
UNIV_INLINE void * mem_alloc_func(ulint n, ulint *size, const char *file_name, ulint line)
#define UT_LIST_NODE_T(TYPE)
Definition ut0lst.h:73
#define UT_LIST_BASE_NODE_T(TYPE)
Definition ut0lst.h:54