drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled::memory::Root Class Reference
Collaboration diagram for drizzled::memory::Root:
[legend]

Public Member Functions

 Root (size_t block_size_arg)
void reset_defaults (size_t block_size, size_t prealloc_size)
unsigned char * alloc (size_t Size)
 Allocate a chunk of memory from the Root structure provided, obtaining more memory from the heap if necessary.
void mark_blocks_free ()
 Mark all data in blocks free for reusage.
void * memdup (const void *, size_t)
 Duplicate the provided block into memory allocated from within the specified Root.
char * strdup (const char *)
 Duplicate a null-terminated string into memory allocated from within the specified Root.
char * strdup (const char *, size_t)
 Copy the (not necessarily null-terminated) string into memory allocated from within the specified Root.
char * strdup (str_ref)
void init (size_t block_size=ROOT_MIN_BLOCK_SIZE)
 Initialize memory root.
bool alloc_root_inited () const
void free_root (myf MyFLAGS)
 Deallocate everything used by alloc_root or just move used blocks to free list if called with MY_USED_TO_FREE.
void * multi_alloc (int unused,...)
 Allocate many pointers at the same time.
void * calloc (size_t size)

Public Attributes

internal::UsedMemory * free
internal::UsedMemory * used
internal::UsedMemory * pre_alloc
size_t min_malloc
size_t block_size
 initial block size
unsigned int block_num
 allocated blocks counter
unsigned int first_block_usage

Detailed Description

Definition at line 57 of file root.h.

Constructor & Destructor Documentation

◆ Root() [1/2]

drizzled::memory::Root::Root ( )
inline

Definition at line 60 of file root.h.

◆ Root() [2/2]

drizzled::memory::Root::Root ( size_t block_size_arg)
inline

Definition at line 70 of file root.h.

Member Function Documentation

◆ alloc()

unsigned char * drizzled::memory::Root::alloc ( 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()
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 140 of file root.cc.

◆ alloc_root_inited()

bool drizzled::memory::Root::alloc_root_inited ( ) const
inline

Definition at line 118 of file root.h.

◆ calloc()

void * drizzled::memory::Root::calloc ( size_t size)
inline

Definition at line 125 of file root.h.

◆ free_root()

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

Deallocate everything used by 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() 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 287 of file root.cc.

◆ init()

void drizzled::memory::Root::init ( 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() 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 ROOT_MIN_BLOCK_SIZE)

Definition at line 57 of file root.cc.

◆ mark_blocks_free()

void drizzled::memory::Root::mark_blocks_free ( )

Mark all data in blocks free for reusage.

Definition at line 245 of file root.cc.

◆ memdup()

void * drizzled::memory::Root::memdup ( 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 365 of file root.cc.

◆ multi_alloc()

void * drizzled::memory::Root::multi_alloc ( 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 212 of file root.cc.

◆ reset_defaults()

void drizzled::memory::Root::reset_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 81 of file root.cc.

◆ strdup() [1/3]

char * drizzled::memory::Root::strdup ( const char * str)

Duplicate a null-terminated string into memory allocated from within the specified Root.

Definition at line 327 of file root.cc.

◆ strdup() [2/3]

char * drizzled::memory::Root::strdup ( 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 343 of file root.cc.

◆ strdup() [3/3]

char * drizzled::memory::Root::strdup ( str_ref v)

Definition at line 351 of file root.cc.

Member Data Documentation

◆ block_num

unsigned int drizzled::memory::Root::block_num

allocated blocks counter

Definition at line 100 of file root.h.

◆ block_size

size_t drizzled::memory::Root::block_size

initial block size

Definition at line 99 of file root.h.

◆ first_block_usage

unsigned int drizzled::memory::Root::first_block_usage

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 106 of file root.h.

◆ free

internal::UsedMemory* drizzled::memory::Root::free

blocks with free memory in it

Definition at line 82 of file root.h.

◆ min_malloc

size_t drizzled::memory::Root::min_malloc

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

Definition at line 97 of file root.h.

◆ pre_alloc

internal::UsedMemory* drizzled::memory::Root::pre_alloc

preallocated block

Definition at line 92 of file root.h.

◆ used

internal::UsedMemory* drizzled::memory::Root::used

blocks almost without free memory

Definition at line 87 of file root.h.


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