25#include <drizzled/internal/my_sys.h>
26#include <drizzled/internal/m_string.h>
27#include <drizzled/sql_string.h>
36static const unsigned int MAX_BLOCK_TO_DROP= 4096;
37static const unsigned int MAX_BLOCK_USAGE_BEFORE_DROP= 10;
61 block_size= block_size_arg - ROOT_MIN_BLOCK_SIZE;
83 block_size= block_size_arg - ROOT_MIN_BLOCK_SIZE;
97 if (mem->size == size)
115 mem->left= pre_alloc_size;
143 assert(alloc_root_inited());
145 length= ALIGN_SIZE(length);
149 if ((*prev)->left < length &&
150 this->first_block_usage++ >= MAX_BLOCK_USAGE_BEFORE_DROP &&
151 (*prev)->left < MAX_BLOCK_TO_DROP)
155 next->next= this->
used;
159 for (next= *prev; next && next->left < length; next= next->next)
166 get_size= max(get_size, tmp_block_size);
171 next->size= get_size;
176 unsigned char* point= (
unsigned char*) ((
char*) next+ (next->size-next->left));
178 if ((next->left-= length) < this->min_malloc)
181 next->next= this->
used;
215 char* *ptr, *start, *res;
216 size_t tot_length, length;
218 va_start(args, unused);
220 while ((ptr= va_arg(args,
char* *)))
222 length= va_arg(args, uint);
223 tot_length+= ALIGN_SIZE(length);
227 start= (
char*) this->
alloc(tot_length);
229 va_start(args, unused);
231 while ((ptr= va_arg(args,
char* *)))
234 length= va_arg(args, uint);
235 res+= ALIGN_SIZE(length);
238 return((
void*) start);
252 for (next=
free; next; next= *(last= &next->next))
261 for (; next; next= next->next)
289 if (MyFlags & MARK_BLOCKS_FREE)
294 if (!(MyFlags & KEEP_PREALLOC))
329 return strdup(str, strlen(str));
345 char* pos= (
char*)
alloc(len + 1);
346 memcpy(pos, str, len);
353 return strdup(v.data(), v.size());
367 void* pos=
alloc(len);
368 memcpy(pos, str, len);
unsigned char * alloc(size_t Size)
Allocate a chunk of memory from the Root structure provided, obtaining more memory from the heap if n...
void free_root(myf MyFLAGS)
Deallocate everything used by alloc_root or just move used blocks to free list if called with MY_USED...
void * memdup(const void *, size_t)
Duplicate the provided block into memory allocated from within the specified Root.
unsigned int block_num
allocated blocks counter
unsigned int first_block_usage
void * multi_alloc(int unused,...)
Allocate many pointers at the same time.
void mark_blocks_free()
Mark all data in blocks free for reusage.
size_t block_size
initial block size
char * strdup(const char *)
Duplicate a null-terminated string into memory allocated from within the specified Root.
internal::UsedMemory * free
void reset_defaults(size_t block_size, size_t prealloc_size)
internal::UsedMemory * used
internal::UsedMemory * pre_alloc
void init(size_t block_size=ROOT_MIN_BLOCK_SIZE)
Initialize memory root.
TODO: Rename this file - func.h is stupid.
Memory root declarations.