1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*****************************************************************************
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/**************************************************//**
@file include/mem0pool.h
The lowest-level memory management
Created 6/9/1994 Heikki Tuuri
*******************************************************/
#ifndef mem0pool_h
#define mem0pool_h
#include "univ.i"
#include "os0file.h"
#include "ut0lst.h"
/** Memory area header */
typedef struct mem_area_struct mem_area_t;
/** Memory pool */
typedef struct mem_pool_struct mem_pool_t;
/** The common memory pool */
extern mem_pool_t* mem_comm_pool;
/** Memory area header */
struct mem_area_struct{
ulint size_and_free; /*!< memory area size is obtained by
anding with ~MEM_AREA_FREE; area in
a free list if ANDing with
MEM_AREA_FREE results in nonzero */
UT_LIST_NODE_T(mem_area_t)
free_list; /*!< free list node */
};
/** Each memory area takes this many extra bytes for control information */
#define MEM_AREA_EXTRA_SIZE (ut_calc_align(sizeof(struct mem_area_struct),\
UNIV_MEM_ALIGNMENT))
/********************************************************************//**
Creates a memory pool.
@return memory pool */
UNIV_INTERN
mem_pool_t*
mem_pool_create(
/*============*/
ulint size); /*!< in: pool size in bytes */
/********************************************************************//**
Allocates memory from a pool. NOTE: This low-level function should only be
used in mem0mem.*!
@return own: allocated memory buffer */
UNIV_INTERN
void*
mem_area_alloc(
/*===========*/
ulint* psize, /*!< in: requested size in bytes; for optimum
space usage, the size should be a power of 2
minus MEM_AREA_EXTRA_SIZE;
out: allocated size in bytes (greater than
or equal to the requested size) */
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Frees memory to a pool. */
UNIV_INTERN
void
mem_area_free(
/*==========*/
void* ptr, /*!< in, own: pointer to allocated memory
buffer */
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Returns the amount of reserved memory.
@return reserved mmeory in bytes */
UNIV_INTERN
ulint
mem_pool_get_reserved(
/*==================*/
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Reserves the mem pool mutex. */
UNIV_INTERN
void
mem_pool_mutex_enter(void);
/*======================*/
/********************************************************************//**
Releases the mem pool mutex. */
UNIV_INTERN
void
mem_pool_mutex_exit(void);
/*=====================*/
/********************************************************************//**
Validates a memory pool.
@return TRUE if ok */
UNIV_INTERN
ibool
mem_pool_validate(
/*==============*/
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Prints info of a memory pool. */
UNIV_INTERN
void
mem_pool_print_info(
/*================*/
FILE* outfile,/*!< in: output file to write to */
mem_pool_t* pool); /*!< in: memory pool */
#ifndef UNIV_NONINL
#include "mem0pool.ic"
#endif
#endif
|