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
23
#ifndef DRIZZLED_MEMORY_ROOT_H
24
#define DRIZZLED_MEMORY_ROOT_H
28
#include <drizzled/definitions.h>
30
#include "drizzled/visibility.h"
36
* @namespace drizzled::memory
37
* Memory allocation utils
39
* NB: This namespace documentation may not seem very useful, but without a
40
* comment on the namespace Doxygen won't extract any documentation for
46
static const int KEEP_PREALLOC= 1;
47
/* move used to free list and reuse them */
48
static const int MARK_BLOCKS_FREE= 2;
54
{ /* struct for once_alloc (block) */
56
UsedMemory *next; /* Next block in use */
57
size_t left; /* memory left in block */
58
size_t size; /* size of block */
63
static const size_t ROOT_MIN_BLOCK_SIZE= (MALLOC_OVERHEAD + sizeof(internal::UsedMemory) + 8);
67
class DRIZZLED_API Root
82
Root(size_t block_size_arg)
84
free= used= pre_alloc= 0;
86
block_size= block_size_arg - memory::ROOT_MIN_BLOCK_SIZE;
87
block_num= 4; /* We shift this with >>2 */
95
* blocks with free memory in it
97
internal::UsedMemory *free;
100
* blocks almost without free memory
102
internal::UsedMemory *used;
107
internal::UsedMemory *pre_alloc;
110
* if block have less memory it will be put in 'used' list
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Data structures for mysys/my_alloc.c (root memory allocator)
23
#define ALLOC_MAX_BLOCK_TO_DROP 4096
24
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
26
typedef struct st_used_mem
27
{ /* struct for once_alloc (block) */
28
struct st_used_mem *next; /* Next block in use */
29
unsigned int left; /* memory left in block */
30
unsigned int size; /* size of block */
34
typedef struct st_mem_root
36
USED_MEM *free; /* blocks with free memory in it */
37
USED_MEM *used; /* blocks almost without free memory */
38
USED_MEM *pre_alloc; /* preallocated block */
39
/* if block have less memory it will be put in 'used' list */
112
40
size_t min_malloc;
114
size_t block_size; ///< initial block size
115
unsigned int block_num; ///< allocated blocks counter
118
* first free block in queue test counter (if it exceed
119
* MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
41
size_t block_size; /* initial block size */
42
unsigned int block_num; /* allocated blocks counter */
44
first free block in queue test counter (if it exceed
45
MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
121
47
unsigned int first_block_usage;
123
49
void (*error_handler)(void);
124
void reset_root_defaults(size_t block_size, size_t prealloc_size);
125
void *alloc_root(size_t Size);
126
inline void *allocate(size_t Size)
128
return alloc_root(Size);
130
void mark_blocks_free();
131
void *memdup_root(const void *str, size_t len);
132
char *strdup_root(const char *str);
134
char *strmake_root(const char *str,size_t len);
135
void init_alloc_root(size_t block_size= ROOT_MIN_BLOCK_SIZE);
137
inline void *duplicate(const void *str, size_t len)
139
return memdup_root(str, len);
142
inline bool alloc_root_inited()
144
return min_malloc != 0;
146
void free_root(myf MyFLAGS);
147
void *multi_alloc_root(int unused, ...);
150
} /* namespace memory */
151
} /* namespace drizzled */
153
#endif /* DRIZZLED_MEMORY_ROOT_H */