MySQL 8.0.39
Source Code Documentation
mem0mem.ic File Reference

The memory management. More...

#include "ut0new.h"

Functions

mem_block_tmem_heap_create_block (mem_heap_t *heap, ulint n, const char *file_name, ulint line, ulint type)
 Creates a memory heap block where data can be allocated. More...
 
void mem_heap_block_free (mem_heap_t *heap, mem_block_t *block)
 Frees a block from a memory heap. More...
 
void mem_heap_free_block_free (mem_heap_t *heap)
 Frees the free_block field from a memory heap. More...
 
mem_block_tmem_heap_add_block (mem_heap_t *heap, ulint n)
 Adds a new block to a memory heap. More...
 
static void mem_block_set_len (mem_block_t *block, ulint len)
 
static ulint mem_block_get_len (mem_block_t *block)
 
static void mem_block_set_type (mem_block_t *block, ulint type)
 
static ulint mem_block_get_type (mem_block_t *block)
 
static void mem_block_set_free (mem_block_t *block, ulint free)
 
static ulint mem_block_get_free (mem_block_t *block)
 
static void mem_block_set_start (mem_block_t *block, ulint start)
 
static ulint mem_block_get_start (mem_block_t *block)
 
static void mem_block_validate (const mem_block_t *block)
 Checks that an object is a memory heap (or a block of it) More...
 
static void * mem_heap_zalloc (mem_heap_t *heap, ulint n)
 Allocates and zero-fills n bytes of memory from a memory heap. More...
 
static void * mem_heap_alloc (mem_heap_t *heap, ulint n)
 Allocates n bytes of memory from a memory heap. More...
 
static void validate_no_mans_land (byte *no_mans_land_begin, byte mem_no_mans_land_byte)
 
static bytemem_heap_get_heap_top (mem_heap_t *heap)
 Returns a pointer to the heap top. More...
 
static void mem_heap_free_heap_top (mem_heap_t *heap, byte *old_top)
 Frees the space in a memory heap exceeding the pointer given. More...
 
static void mem_heap_empty (mem_heap_t *heap)
 Empties a memory heap. More...
 
static void * mem_heap_get_top (mem_heap_t *heap, ulint n)
 Returns a pointer to the topmost element in a memory heap. More...
 
static bool mem_heap_is_top (mem_heap_t *heap, const void *buf, ulint buf_sz)
 Checks if a given chunk of memory is the topmost element stored in the heap. More...
 
static void * mem_heap_replace (mem_heap_t *heap, const void *top, ulint top_sz, ulint new_sz)
 Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element. More...
 
static void * mem_heap_dup_replace (mem_heap_t *heap, const void *top, ulint top_sz, const void *data, ulint data_sz)
 Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element and then copy the specified data to it. More...
 
static char * mem_heap_strdup_replace (mem_heap_t *heap, const void *top, ulint top_sz, const char *str)
 Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element and then copy the specified string to it. More...
 
static void mem_heap_free_top (mem_heap_t *heap, ulint n)
 Frees the topmost element in a memory heap. More...
 
static mem_heap_tmem_heap_create (ulint size, ut::Location loc, ulint type)
 
static void mem_heap_free (mem_heap_t *heap)
 Frees the space occupied by a memory heap. More...
 
static size_t mem_heap_get_size (mem_heap_t *heap)
 Returns the space in bytes occupied by a memory heap. More...
 
static char * mem_strdup (const char *str)
 Duplicates a NUL-terminated string. More...
 
static char * mem_strdupl (const char *str, ulint len)
 Makes a NUL-terminated copy of a nonterminated string. More...
 
static char * mem_heap_strdupl (mem_heap_t *heap, const char *str, ulint len)
 Makes a NUL-terminated copy of a nonterminated string, allocated from a memory heap. More...
 

Detailed Description

The memory management.

Created 6/8/1994 Heikki Tuuri

Function Documentation

◆ mem_block_get_free()

static ulint mem_block_get_free ( mem_block_t block)
inlinestatic

◆ mem_block_get_len()

static ulint mem_block_get_len ( mem_block_t block)
inlinestatic

◆ mem_block_get_start()

static ulint mem_block_get_start ( mem_block_t block)
inlinestatic

◆ mem_block_get_type()

static ulint mem_block_get_type ( mem_block_t block)
inlinestatic

◆ mem_block_set_free()

static void mem_block_set_free ( mem_block_t block,
ulint  free 
)
inlinestatic

◆ mem_block_set_len()

static void mem_block_set_len ( mem_block_t block,
ulint  len 
)
inlinestatic

◆ mem_block_set_start()

static void mem_block_set_start ( mem_block_t block,
ulint  start 
)
inlinestatic

◆ mem_block_set_type()

static void mem_block_set_type ( mem_block_t block,
ulint  type 
)
inlinestatic

◆ mem_block_validate()

static void mem_block_validate ( const mem_block_t block)
inlinestatic

Checks that an object is a memory heap (or a block of it)

Parameters
[in]blockMemory heap to check

◆ mem_heap_add_block()

mem_block_t * mem_heap_add_block ( mem_heap_t heap,
ulint  n 
)

Adds a new block to a memory heap.

Parameters
[in]heapmemory heap
[in]nnumber of bytes needed
Returns
created block, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)
created block, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)
Parameters
heapin: memory heap
nin: number of bytes user needs

◆ mem_heap_alloc()

static void * mem_heap_alloc ( mem_heap_t heap,
ulint  n 
)
inlinestatic

Allocates n bytes of memory from a memory heap.

Parameters
[in]heapmemory heap
[in]nnumber of bytes; if the heap is allowed to grow into the buffer pool, this must be <= MEM_MAX_ALLOC_IN_BUF
Returns
allocated storage, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)

◆ mem_heap_block_free()

void mem_heap_block_free ( mem_heap_t heap,
mem_block_t block 
)

Frees a block from a memory heap.

in: block to free

Parameters
heapin: heap
blockin: block to free

◆ mem_heap_create()

static mem_heap_t * mem_heap_create ( ulint  size,
ut::Location  loc,
ulint  type 
)
inlinestatic

◆ mem_heap_create_block()

mem_block_t * mem_heap_create_block ( mem_heap_t heap,
ulint  n,
const char *  file_name,
ulint  line,
ulint  type 
)

Creates a memory heap block where data can be allocated.

Returns
own: memory heap block, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)
Parameters
[in]heapmemory heap or NULL if first block should be created
[in]nnumber od bytes needed for user data
[in]file_namefile name where created
[in]lineline where created
[in]typetype of heap MEM_HEAP_DYNAMIC or MEM_HEAP_BUFFER

◆ mem_heap_dup_replace()

static void * mem_heap_dup_replace ( mem_heap_t heap,
const void *  top,
ulint  top_sz,
const void *  data,
ulint  data_sz 
)
inlinestatic

Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element and then copy the specified data to it.

If the memory chunk specified with (top, top_sz) is the topmost element, then it will be discarded, otherwise it will be left untouched and this function will be equivallent to mem_heap_dup().

Returns
allocated storage, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)
Parameters
heapin/out: memory heap
topin: chunk to discard if possible
top_szin: size of top in bytes
datain: new data to duplicate
data_szin: size of data in bytes

◆ mem_heap_empty()

static void mem_heap_empty ( mem_heap_t heap)
inlinestatic

Empties a memory heap.

The first memory block of the heap is not freed.

Parameters
[in]heapheap to empty

◆ mem_heap_free()

static void mem_heap_free ( mem_heap_t heap)
inlinestatic

Frees the space occupied by a memory heap.

NOTE: Use the corresponding macro instead of this function.

Parameters
[in]heapHeap to be freed

◆ mem_heap_free_block_free()

void mem_heap_free_block_free ( mem_heap_t heap)

Frees the free_block field from a memory heap.

in: heap

Parameters
heapin: heap

◆ mem_heap_free_heap_top()

static void mem_heap_free_heap_top ( mem_heap_t heap,
byte old_top 
)
inlinestatic

Frees the space in a memory heap exceeding the pointer given.

The pointer must have been acquired from mem_heap_get_heap_top. The first memory block of the heap is not freed.

Parameters
[in]heapheap from which to free
[in]old_toppointer to old top of heap

◆ mem_heap_free_top()

static void mem_heap_free_top ( mem_heap_t heap,
ulint  n 
)
inlinestatic

Frees the topmost element in a memory heap.

The size of the element must be given.

Parameters
heapin: memory heap
nin: size of the topmost element

◆ mem_heap_get_heap_top()

static byte * mem_heap_get_heap_top ( mem_heap_t heap)
inlinestatic

Returns a pointer to the heap top.

Parameters
[in]heapmemory heap
Returns
pointer to the heap top

◆ mem_heap_get_size()

static size_t mem_heap_get_size ( mem_heap_t heap)
inlinestatic

Returns the space in bytes occupied by a memory heap.

Parameters
heapin: heap

◆ mem_heap_get_top()

static void * mem_heap_get_top ( mem_heap_t heap,
ulint  n 
)
inlinestatic

Returns a pointer to the topmost element in a memory heap.

The size of the element must be given.

Parameters
[in]heapmemory heap
[in]nsize of the topmost element
Returns
pointer to the topmost element

◆ mem_heap_is_top()

static bool mem_heap_is_top ( mem_heap_t heap,
const void *  buf,
ulint  buf_sz 
)
inlinestatic

Checks if a given chunk of memory is the topmost element stored in the heap.

If this is the case, then calling mem_heap_free_top() would free that element from the heap.

Parameters
[in]heapmemory heap
[in]bufpresumed topmost element
[in]buf_szsize of buf in bytes
Returns
true if topmost

◆ mem_heap_replace()

static void * mem_heap_replace ( mem_heap_t heap,
const void *  top,
ulint  top_sz,
ulint  new_sz 
)
inlinestatic

Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element.

If the memory chunk specified with (top, top_sz) is the topmost element, then it will be discarded, otherwise it will be left untouched and this function will be equivallent to mem_heap_alloc().

Returns
allocated storage, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)
Parameters
heapin/out: memory heap
topin: chunk to discard if possible
top_szin: size of top in bytes
new_szin: desired size of the new chunk

◆ mem_heap_strdup_replace()

static char * mem_heap_strdup_replace ( mem_heap_t heap,
const void *  top,
ulint  top_sz,
const char *  str 
)
inlinestatic

Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element and then copy the specified string to it.

If the memory chunk specified with (top, top_sz) is the topmost element, then it will be discarded, otherwise it will be left untouched and this function will be equivallent to mem_heap_strdup().

Returns
allocated string, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)
Parameters
heapin/out: memory heap
topin: chunk to discard if possible
top_szin: size of top in bytes
strin: new data to duplicate

◆ mem_heap_strdupl()

static char * mem_heap_strdupl ( mem_heap_t heap,
const char *  str,
ulint  len 
)
inlinestatic

Makes a NUL-terminated copy of a nonterminated string, allocated from a memory heap.

Returns
own: a copy of the string
Parameters
heapin: memory heap where string is allocated
strin: string to be copied
lenin: length of str, in bytes

◆ mem_heap_zalloc()

static void * mem_heap_zalloc ( mem_heap_t heap,
ulint  n 
)
inlinestatic

Allocates and zero-fills n bytes of memory from a memory heap.

Parameters
[in]heapmemory heap
[in]nnumber of bytes; if the heap is allowed to grow into the buffer pool, this must be <= MEM_MAX_ALLOC_IN_BUF
Returns
allocated, zero-filled storage

◆ mem_strdup()

static char * mem_strdup ( const char *  str)
inlinestatic

Duplicates a NUL-terminated string.

Returns
own: a copy of the string, must be deallocated with ut_free
Parameters
strin: string to be copied

◆ mem_strdupl()

static char * mem_strdupl ( const char *  str,
ulint  len 
)
inlinestatic

Makes a NUL-terminated copy of a nonterminated string.

Returns
own: a copy of the string, must be deallocated with ut_free
Parameters
strin: string to be copied
lenin: length of str, in bytes

◆ validate_no_mans_land()

static void validate_no_mans_land ( byte no_mans_land_begin,
byte  mem_no_mans_land_byte 
)
inlinestatic