MySQL 8.0.40
Source Code Documentation
memory.cc File Reference

The memory management. More...

#include "ha_prototypes.h"
#include "mem0mem.h"
#include "buf0buf.h"
#include "srv0srv.h"
#include <stdarg.h>

Functions

char * mem_heap_strdup (mem_heap_t *heap, const char *str)
 Duplicates a NUL-terminated string, allocated from a memory heap. More...
 
void * mem_heap_dup (mem_heap_t *heap, const void *data, ulint len)
 Duplicate a block of data, allocated from a memory heap. More...
 
char * mem_heap_strcat (mem_heap_t *heap, const char *s1, const char *s2)
 Concatenate two strings and return the result, using a memory heap. More...
 
static ulint mem_heap_printf_low (char *buf, const char *format, va_list ap)
 Helper function for mem_heap_printf. More...
 
char * mem_heap_printf (mem_heap_t *heap, const char *format,...)
 A simple sprintf replacement that dynamically allocates the space for the formatted string from the given heap. More...
 
void mem_heap_validate (const mem_heap_t *heap)
 Validates the contents of a memory heap. More...
 
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...
 
mem_block_tmem_heap_add_block (mem_heap_t *heap, ulint n)
 Adds a new block to a memory heap. 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...
 

Detailed Description

The memory management.

Created 6/9/1994 Heikki Tuuri

Function Documentation

◆ 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.

Returns
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_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_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()

void * mem_heap_dup ( mem_heap_t heap,
const void *  data,
ulint  len 
)

Duplicate a block of data, allocated from a memory heap.

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

◆ 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_printf()

char * mem_heap_printf ( mem_heap_t heap,
const char *  format,
  ... 
)

A simple sprintf replacement that dynamically allocates the space for the formatted string from the given heap.

This supports a very limited set of the printf syntax: types 's' and 'u' and length modifier 'l' (which is required for the 'u' type).

Returns
heap-allocated formatted string
Parameters
heapin: memory heap
formatin: format string

◆ mem_heap_printf_low()

static ulint mem_heap_printf_low ( char *  buf,
const char *  format,
va_list  ap 
)
static

Helper function for mem_heap_printf.

Returns
length of formatted string, including terminating NUL
Parameters
bufin/out: buffer to store formatted string in, or NULL to just calculate length
formatin: format string
apin: arguments

◆ mem_heap_strcat()

char * mem_heap_strcat ( mem_heap_t heap,
const char *  s1,
const char *  s2 
)

Concatenate two strings and return the result, using a memory heap.

Returns
own: the result
Parameters
heapin: memory heap where string is allocated
s1in: string 1
s2in: string 2

◆ mem_heap_strdup()

char * mem_heap_strdup ( mem_heap_t heap,
const char *  str 
)

Duplicates a NUL-terminated string, allocated from a memory heap.

Parameters
[in]heapmemory heap where string is allocated
[in]strstring to be copied
Returns
own: a copy of the string

◆ mem_heap_validate()

void mem_heap_validate ( const mem_heap_t heap)

Validates the contents of a memory heap.

Checks a memory heap for consistency, prints the contents if any error is detected. A fatal error is logged if an error is detected.

Parameters
[in]heapMemory heap to validate.