Drizzled Public API Documentation

drizzled::memory::Root Class Reference

List of all members.

Public Member Functions

 Root (size_t block_size_arg)
void reset_root_defaults (size_t block_size, size_t prealloc_size)
void * alloc_root (size_t Size)
 Allocate a chunk of memory from the Root structure provided, obtaining more memory from the heap if necessary.
void * allocate (size_t Size)
void mark_blocks_free ()
 Mark all data in blocks free for reusage.
void * memdup_root (const void *str, size_t len)
 Duplicate the provided block into memory allocated from within the specified Root.
char * strdup_root (const char *str)
 Duplicate a null-terminated string into memory allocated from within the specified Root.
char * strmake_root (const char *str, size_t len)
 Copy the (not necessarily null-terminated) string into memory allocated from within the specified Root.
void init_alloc_root (size_t block_size=ROOT_MIN_BLOCK_SIZE)
 Initialize memory root.
void * duplicate (const void *str, size_t len)
bool alloc_root_inited ()
void free_root (myf MyFLAGS)
 Deallocate everything used by memory::alloc_root or just move used blocks to free list if called with MY_USED_TO_FREE.
void * multi_alloc_root (int unused,...)
 Allocate many pointers at the same time.

Public Attributes

internal::UsedMemoryfree
internal::UsedMemoryused
internal::UsedMemorypre_alloc
size_t min_malloc
size_t block_size
 initial block size
unsigned int block_num
 allocated blocks counter
unsigned int first_block_usage
void(* error_handler )(void)

Detailed Description

Definition at line 66 of file root.h.


Member Function Documentation

void * drizzled::memory::Root::alloc_root ( size_t  length)

Allocate a chunk of memory from the Root structure provided, obtaining more memory from the heap if necessary.

Precondition:
mem_root must have been initialised via init_alloc_root()
Parameters:
mem_rootThe memory Root to allocate from
lengthThe size of the block to allocate
Todo:
Would this be more suitable as a member function on the Root class?
Todo:
next part may be unneeded due to this->first_block_usage counter

Definition at line 149 of file root.cc.

void drizzled::memory::Root::free_root ( myf  MyFlags)

Deallocate everything used by memory::alloc_root or just move used blocks to free list if called with MY_USED_TO_FREE.

Note:
One can call this function either with root block initialised with init_alloc_root() or with a zero:ed block. It's also safe to call this multiple times with the same mem_root.
Parameters:
rootMemory root
MyFlagsFlags for what should be freed:
  • MARK_BLOCKS_FREED Don't free blocks, just mark them free
  • KEEP_PREALLOC If this is not set, then free also the preallocated block

Definition at line 313 of file root.cc.

Referenced by drizzled::dispatch_command(), drizzled::my_print_help_inc_plugins(), and HailDBCursor::reset().

void drizzled::memory::Root::init_alloc_root ( size_t  block_size_arg = ROOT_MIN_BLOCK_SIZE)

Initialize memory root.

This function prepares memory root for further use, sets initial size of chunk for memory allocation and pre-allocates first block if specified. Altough error can happen during execution of this function if pre_alloc_size is non-0 it won't be reported. Instead it will be reported as error in first alloc_root() on this memory root.

Parameters:
mem_rootmemory root to initialize
block_sizesize of chunks (blocks) used for memory allocation (It is external size of chunk i.e. it should include memory required for internal structures, thus it should be no less than memory::ROOT_MIN_BLOCK_SIZE)

Definition at line 54 of file root.cc.

void * drizzled::memory::Root::memdup_root ( const void *  str,
size_t  len 
)

Duplicate the provided block into memory allocated from within the specified Root.

Returns:
non-NULL pointer to a copy of the data if memory could be allocated, otherwise NULL

Definition at line 390 of file root.cc.

Referenced by drizzled::Field::clone().

void * drizzled::memory::Root::multi_alloc_root ( int  unused,
  ... 
)

Allocate many pointers at the same time.

The variable arguments are a list of alternating pointers and lengths, terminated by a null pointer:

  • char ** pointer1
  • uint length1
  • char ** pointer2
  • uint length2
  • ...
  • NULL

pointer1, pointer2 etc. all point into big allocated memory area

Parameters:
rootMemory root
Returns:
A pointer to the beginning of the allocated memory block in case of success or NULL if out of memory

Definition at line 229 of file root.cc.

void drizzled::memory::Root::reset_root_defaults ( size_t  block_size_arg,
size_t  pre_alloc_size 
)

Function aligns and assigns new value to block size; then it tries to reuse one of existing blocks as prealloc block, or malloc new one of requested size. If no blocks can be reused, all unused blocks are freed before allocation.

Parameters:
mem_rootmemory root to change defaults of
block_sizenew value of block size. Must be greater or equal than ALLOC_ROOT_MIN_BLOCK_SIZE (this value is about 68 bytes and depends on platform and compilation flags)
pre_alloc_sizenew size of preallocated block. If not zero, must be equal to or greater than block size, otherwise means 'no prealloc'.

Definition at line 84 of file root.cc.

Referenced by drizzled::Session::prepareForQueries().

char * drizzled::memory::Root::strmake_root ( const char *  str,
size_t  len 
)

Copy the (not necessarily null-terminated) string into memory allocated from within the specified Root.

Note that the string is copied according to the length specified, so null-termination is ignored. The duplicated string will be null-terminated, even if the original string wasn't (one additional byte is allocated for this purpose).

Definition at line 370 of file root.cc.

Referenced by drizzled::prepare_create_table().


Member Data Documentation

first free block in queue test counter (if it exceed MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)

Definition at line 120 of file root.h.

blocks with free memory in it

Definition at line 96 of file root.h.

if block have less memory it will be put in 'used' list

Definition at line 111 of file root.h.

preallocated block

Definition at line 106 of file root.h.

blocks almost without free memory

Definition at line 101 of file root.h.


The documentation for this class was generated from the following files: