28
#define MY_KEEP_PREALLOC 1
29
#define MY_MARK_BLOCKS_FREE 2 /* move used to free list and reuse them */
31
#define alloc_root_inited(A) ((A)->min_malloc != 0)
32
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
33
#define ALLOC_MAX_BLOCK_TO_DROP 4096
34
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
36
typedef struct st_used_mem
37
{ /* struct for once_alloc (block) */
38
struct st_used_mem *next; /* Next block in use */
39
size_t left; /* memory left in block */
40
size_t size; /* size of block */
44
typedef struct st_mem_root
46
USED_MEM *free; /* blocks with free memory in it */
47
USED_MEM *used; /* blocks almost without free memory */
48
USED_MEM *pre_alloc; /* preallocated block */
33
static const int KEEP_PREALLOC= 1;
34
/* move used to free list and reuse them */
35
static const int MARK_BLOCKS_FREE= 2;
41
{ /* struct for once_alloc (block) */
43
UsedMemory *next; /* Next block in use */
44
size_t left; /* memory left in block */
45
size_t size; /* size of block */
50
static const size_t ROOT_MIN_BLOCK_SIZE= (MALLOC_OVERHEAD + sizeof(internal::UsedMemory) + 8);
57
/* blocks with free memory in it */
58
internal::UsedMemory *free;
60
/* blocks almost without free memory */
61
internal::UsedMemory *used;
63
/* preallocated block */
64
internal::UsedMemory *pre_alloc;
49
66
/* if block have less memory it will be put in 'used' list */
51
68
size_t block_size; /* initial block size */
57
74
unsigned int first_block_usage;
59
76
void (*error_handler)(void);
62
void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
63
size_t pre_alloc_size);
64
void *alloc_root(MEM_ROOT *mem_root, size_t Size);
65
void *multi_alloc_root(MEM_ROOT *mem_root, ...);
66
void free_root(MEM_ROOT *root, myf MyFLAGS);
67
void set_prealloc_root(MEM_ROOT *root, char *ptr);
68
void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
79
inline static bool alloc_root_inited(Root *root)
81
return root->min_malloc != 0;
84
void init_alloc_root(Root *mem_root,
85
size_t block_size= ROOT_MIN_BLOCK_SIZE);
86
void *alloc_root(Root *mem_root, size_t Size);
87
void *multi_alloc_root(Root *mem_root, ...);
88
void free_root(Root *root, myf MyFLAGS);
89
void set_prealloc_root(Root *root, char *ptr);
90
void reset_root_defaults(Root *mem_root, size_t block_size,
69
91
size_t prealloc_size);
70
char *strdup_root(MEM_ROOT *root,const char *str);
71
char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
72
void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
92
char *strdup_root(Root *root,const char *str);
93
char *strmake_root(Root *root,const char *str,size_t len);
94
void *memdup_root(Root *root,const void *str, size_t len);
74
99
#if defined(__cplusplus)