12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18
* @brief Memory root declarations
21
#ifndef DRIZZLED_MEMORY_ROOT_H
22
#define DRIZZLED_MEMORY_ROOT_H
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Data structures for mysys/my_alloc.c (root memory allocator)
26
24
#include <drizzled/definitions.h>
32
* @namespace drizzled::memory
33
* Memory allocation utils
35
* NB: This namespace documentation may not seem very useful, but without a
36
* comment on the namespace Doxygen won't extract any documentation for
42
static const int KEEP_PREALLOC= 1;
43
/* move used to free list and reuse them */
44
static const int MARK_BLOCKS_FREE= 2;
50
{ /* struct for once_alloc (block) */
52
UsedMemory *next; /* Next block in use */
53
size_t left; /* memory left in block */
54
size_t size; /* size of block */
59
static const size_t ROOT_MIN_BLOCK_SIZE= (MALLOC_OVERHEAD + sizeof(internal::UsedMemory) + 8);
78
Root(size_t block_size_arg)
80
free= used= pre_alloc= 0;
82
block_size= block_size_arg - memory::ROOT_MIN_BLOCK_SIZE;
83
block_num= 4; /* We shift this with >>2 */
91
* blocks with free memory in it
93
internal::UsedMemory *free;
96
* blocks almost without free memory
98
internal::UsedMemory *used;
103
internal::UsedMemory *pre_alloc;
106
* if block have less memory it will be put in 'used' list
26
#if defined(__cplusplus)
30
#define ALLOC_MAX_BLOCK_TO_DROP 4096
31
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
33
typedef struct st_used_mem
34
{ /* struct for once_alloc (block) */
35
struct st_used_mem *next; /* Next block in use */
36
unsigned int left; /* memory left in block */
37
unsigned int size; /* size of block */
41
typedef struct st_mem_root
43
USED_MEM *free; /* blocks with free memory in it */
44
USED_MEM *used; /* blocks almost without free memory */
45
USED_MEM *pre_alloc; /* preallocated block */
46
/* if block have less memory it will be put in 'used' list */
108
47
size_t min_malloc;
110
size_t block_size; ///< initial block size
111
unsigned int block_num; ///< allocated blocks counter
114
* first free block in queue test counter (if it exceed
115
* MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
48
size_t block_size; /* initial block size */
49
unsigned int block_num; /* allocated blocks counter */
51
first free block in queue test counter (if it exceed
52
MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
117
54
unsigned int first_block_usage;
119
56
void (*error_handler)(void);
120
void reset_root_defaults(size_t block_size, size_t prealloc_size);
121
void *alloc_root(size_t Size);
122
void mark_blocks_free();
123
void *memdup_root(const void *str, size_t len);
124
char *strdup_root(const char *str);
125
char *strmake_root(const char *str,size_t len);
126
void init_alloc_root(size_t block_size= ROOT_MIN_BLOCK_SIZE);
128
inline bool alloc_root_inited()
130
return min_malloc != 0;
132
void free_root(myf MyFLAGS);
133
void *multi_alloc_root(int unused, ...);
136
} /* namespace memory */
137
} /* namespace drizzled */
139
#endif /* DRIZZLED_MEMORY_ROOT_H */
59
void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
60
size_t pre_alloc_size);
61
void *alloc_root(MEM_ROOT *mem_root, size_t Size);
62
void *multi_alloc_root(MEM_ROOT *mem_root, ...);
63
void free_root(MEM_ROOT *root, myf MyFLAGS);
64
void set_prealloc_root(MEM_ROOT *root, char *ptr);
65
void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
66
size_t prealloc_size);
67
char *strdup_root(MEM_ROOT *root,const char *str);
68
char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
69
void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
71
#if defined(__cplusplus)