drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
mem0mem.h File Reference
#include "univ.i"
#include "ut0mem.h"
#include "ut0byte.h"
#include "ut0rnd.h"
#include "sync0sync.h"
#include "ut0lst.h"
#include "mach0data.h"
#include "mem0dbg.h"
Include dependency graph for mem0mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mem_block_info_struct

Macros

#define mem0mem_h
#define MEM_HEAP_DYNAMIC   0 /* the most common type */
#define MEM_HEAP_BUFFER   1
#define MEM_HEAP_BTR_SEARCH
#define MEM_BLOCK_START_SIZE   64
#define MEM_BLOCK_STANDARD_SIZE    (UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF)
#define MEM_MAX_ALLOC_IN_BUF   (UNIV_PAGE_SIZE - 200)
#define mem_heap_create(N)
#define mem_heap_create_in_buffer(N)
#define mem_heap_create_in_btr_search(N)
#define mem_heap_free(heap)
#define mem_zalloc(N)
#define mem_alloc(N)
#define mem_alloc2(N, S)
#define mem_free(PTR)
#define MEM_BLOCK_MAGIC_N   764741555
#define MEM_FREED_BLOCK_MAGIC_N   547711122
#define MEM_BLOCK_HEADER_SIZE

Typedefs

typedef struct mem_block_info_struct mem_block_info_t
typedef mem_block_info_t mem_block_t
typedef mem_block_t mem_heap_t

Functions

UNIV_INTERN void mem_init (ulint size)
UNIV_INTERN void mem_close (void)
UNIV_INLINE mem_heap_t * mem_heap_create_func (ulint n, ulint type, const char *file_name, ulint line)
UNIV_INLINE void mem_heap_free_func (mem_heap_t *heap, const char *file_name, ulint line)
UNIV_INLINE void * mem_heap_zalloc (mem_heap_t *heap, ulint n)
UNIV_INLINE void * mem_heap_alloc (mem_heap_t *heap, ulint n)
UNIV_INLINE byte * mem_heap_get_heap_top (mem_heap_t *heap)
UNIV_INLINE void mem_heap_free_heap_top (mem_heap_t *heap, byte *old_top)
UNIV_INLINE void mem_heap_empty (mem_heap_t *heap)
UNIV_INLINE void * mem_heap_get_top (mem_heap_t *heap, ulint n)
UNIV_INLINE void mem_heap_free_top (mem_heap_t *heap, ulint n)
UNIV_INLINE ulint mem_heap_get_size (mem_heap_t *heap)
UNIV_INLINE void * mem_alloc_func (ulint n, ulint *size, const char *file_name, ulint line)
UNIV_INLINE void mem_free_func (void *ptr, const char *file_name, ulint line)
UNIV_INLINE char * mem_strdup (const char *str)
UNIV_INLINE char * mem_strdupl (const char *str, ulint len)
UNIV_INTERN char * mem_heap_strdup (mem_heap_t *heap, const char *str)
UNIV_INLINE char * mem_heap_strdupl (mem_heap_t *heap, const char *str, ulint len)
UNIV_INTERN char * mem_heap_strcat (mem_heap_t *heap, const char *s1, const char *s2)
UNIV_INTERN void * mem_heap_dup (mem_heap_t *heap, const void *data, ulint len)
UNIV_INTERN char * mem_heap_printf (mem_heap_t *heap, const char *format,...) __attribute__((format(printf

Detailed Description

The memory management

Created 6/9/1994 Heikki Tuuri

Definition in file mem0mem.h.

Macro Definition Documentation

◆ mem0mem_h

#define mem0mem_h

Definition at line 28 of file mem0mem.h.

◆ mem_alloc

#define mem_alloc ( N)
Value:
mem_alloc_func((N), NULL, __FILE__, __LINE__)
UNIV_INLINE void * mem_alloc_func(ulint n, ulint *size, const char *file_name, ulint line)

Definition at line 221 of file mem0mem.h.

◆ mem_alloc2

#define mem_alloc2 ( N,
S )
Value:
mem_alloc_func((N), (S), __FILE__, __LINE__)

Definition at line 222 of file mem0mem.h.

◆ MEM_BLOCK_HEADER_SIZE

#define MEM_BLOCK_HEADER_SIZE
Value:
ut_calc_align(sizeof(mem_block_info_t),\
UNIV_MEM_ALIGNMENT)
#define ut_calc_align(n, m)
Definition ut0ut.h:187

Definition at line 389 of file mem0mem.h.

◆ MEM_BLOCK_MAGIC_N

#define MEM_BLOCK_MAGIC_N   764741555

Definition at line 385 of file mem0mem.h.

◆ MEM_BLOCK_STANDARD_SIZE

#define MEM_BLOCK_STANDARD_SIZE    (UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF)

Definition at line 66 of file mem0mem.h.

◆ MEM_BLOCK_START_SIZE

#define MEM_BLOCK_START_SIZE   64

Definition at line 65 of file mem0mem.h.

◆ mem_free

#define mem_free ( PTR)
Value:
mem_free_func((PTR), __FILE__, __LINE__)
UNIV_INLINE void mem_free_func(void *ptr, const char *file_name, ulint line)

Use this macro instead of the corresponding function! Macro for memory buffer freeing

Definition at line 243 of file mem0mem.h.

◆ MEM_FREED_BLOCK_MAGIC_N

#define MEM_FREED_BLOCK_MAGIC_N   547711122

Definition at line 386 of file mem0mem.h.

◆ MEM_HEAP_BTR_SEARCH

#define MEM_HEAP_BTR_SEARCH
Value:
2 /* this flag can optionally be
ORed to MEM_HEAP_BUFFER, in which
case heap->free_block is used in
some cases for memory allocations,
and if NULL, the memory
allocation functions can return
NULL. */

Definition at line 58 of file mem0mem.h.

◆ MEM_HEAP_BUFFER

#define MEM_HEAP_BUFFER   1

Definition at line 57 of file mem0mem.h.

◆ mem_heap_create

#define mem_heap_create ( N)
Value:
(N), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
UNIV_INLINE mem_heap_t * mem_heap_create_func(ulint n, ulint type, const char *file_name, ulint line)

Use this macro instead of the corresponding function! Macro for memory heap creation.

Definition at line 91 of file mem0mem.h.

◆ mem_heap_create_in_btr_search

#define mem_heap_create_in_btr_search ( N)
Value:
(N), MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER,\
__FILE__, __LINE__)

Use this macro instead of the corresponding function! Macro for memory heap creation.

Definition at line 103 of file mem0mem.h.

◆ mem_heap_create_in_buffer

#define mem_heap_create_in_buffer ( N)
Value:
(N), MEM_HEAP_BUFFER, __FILE__, __LINE__)

Use this macro instead of the corresponding function! Macro for memory heap creation.

Definition at line 97 of file mem0mem.h.

◆ MEM_HEAP_DYNAMIC

#define MEM_HEAP_DYNAMIC   0 /* the most common type */

Definition at line 56 of file mem0mem.h.

◆ mem_heap_free

#define mem_heap_free ( heap)
Value:
(heap), __FILE__, __LINE__)
UNIV_INLINE void mem_heap_free_func(mem_heap_t *heap, const char *file_name, ulint line)

Use this macro instead of the corresponding function! Macro for memory heap freeing.

Definition at line 111 of file mem0mem.h.

◆ MEM_MAX_ALLOC_IN_BUF

#define MEM_MAX_ALLOC_IN_BUF   (UNIV_PAGE_SIZE - 200)

Definition at line 71 of file mem0mem.h.

◆ mem_zalloc

#define mem_zalloc ( N)
Value:
memset(mem_alloc(N), 0, (N))

Use this macro instead of the corresponding function! Macro for memory buffer allocation

Definition at line 219 of file mem0mem.h.

Typedef Documentation

◆ mem_block_info_t

typedef struct mem_block_info_struct mem_block_info_t

Definition at line 43 of file mem0mem.h.

◆ mem_block_t

typedef mem_block_info_t mem_block_t

Definition at line 47 of file mem0mem.h.

◆ mem_heap_t

typedef mem_block_t mem_heap_t

Definition at line 50 of file mem0mem.h.

Function Documentation

◆ mem_alloc_func()

UNIV_INLINE void * mem_alloc_func ( ulint n,
ulint * size,
const char * file_name,
ulint line )

NOTE: Use the corresponding macro instead of this function. Allocates a single buffer of memory from the dynamic memory of the C compiler. Is like malloc of C. The buffer must be freed with mem_free.

Returns
own: free storage in: line where created
Parameters
nin: requested size in bytes
sizeout: allocated size in bytes, or NULL
file_namein: file name where created

◆ mem_close()

UNIV_INTERN void mem_close ( void )

Closes the memory system.

Definition at line 186 of file mem0dbg.cc.

◆ mem_free_func()

UNIV_INLINE void mem_free_func ( void * ptr,
const char * file_name,
ulint line )

NOTE: Use the corresponding macro instead of this function. Frees a single buffer of storage from the dynamic memory of C compiler. Similar to free of C. in: line where created

Parameters
ptrin, own: buffer to be freed
file_namein: file name where created

◆ mem_heap_alloc()

UNIV_INLINE void * mem_heap_alloc ( mem_heap_t * heap,
ulint n )

Allocates n bytes of memory from a memory heap.

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

◆ mem_heap_create_func()

UNIV_INLINE mem_heap_t * mem_heap_create_func ( ulint n,
ulint type,
const char * file_name,
ulint line )

NOTE: Use the corresponding macros instead of this function. Creates a memory heap. For debugging purposes, takes also the file name and line as arguments.

Returns
own: memory heap, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps) in: line where created
Parameters
nin: desired start block size, this means that a single user buffer of size n will fit in the block, 0 creates a default size block
typein: heap type
file_namein: file name where created

◆ mem_heap_dup()

UNIV_INTERN 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 in: length of data, in bytes

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

Definition at line 117 of file mem0mem.cc.

◆ mem_heap_empty()

UNIV_INLINE void mem_heap_empty ( mem_heap_t * heap)

Empties a memory heap. The first memory block of the heap is not freed. in: heap to empty

◆ mem_heap_free_func()

UNIV_INLINE void mem_heap_free_func ( mem_heap_t * heap,
const char * file_name,
ulint line )

NOTE: Use the corresponding macro instead of this function. Frees the space occupied by a memory heap. In the debug version erases the heap memory blocks. in: line where freed

Parameters
heapin, own: heap to be freed
file_namein: file name where freed

◆ mem_heap_free_heap_top()

UNIV_INLINE void mem_heap_free_heap_top ( mem_heap_t * heap,
byte * old_top )

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. in: pointer to old top of heap

Parameters
heapin: heap from which to free

◆ mem_heap_free_top()

UNIV_INLINE void mem_heap_free_top ( mem_heap_t * heap,
ulint n )

Frees the topmost element in a memory heap. The size of the element must be given. in: size of the topmost element

Parameters
heapin: memory heap

◆ mem_heap_get_heap_top()

UNIV_INLINE byte * mem_heap_get_heap_top ( mem_heap_t * heap)

Returns a pointer to the heap top.

Returns
pointer to the heap top in: memory heap

◆ mem_heap_get_size()

UNIV_INLINE ulint mem_heap_get_size ( mem_heap_t * heap)

Returns the space in bytes occupied by a memory heap. in: heap

◆ mem_heap_get_top()

UNIV_INLINE void * mem_heap_get_top ( mem_heap_t * heap,
ulint n )

Returns a pointer to the topmost element in a memory heap. The size of the element must be given.

Returns
pointer to the topmost element in: size of the topmost element
Parameters
heapin: memory heap

◆ mem_heap_printf()

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

A simple (s)printf 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_strcat()

UNIV_INTERN 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 in: string 2

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

Definition at line 131 of file mem0mem.cc.

◆ mem_heap_strdup()

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

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

Returns
own: a copy of the string in: string to be copied

Duplicates a NUL-terminated 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

Definition at line 104 of file mem0mem.cc.

◆ mem_heap_strdupl()

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

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

◆ mem_heap_zalloc()

UNIV_INLINE void * mem_heap_zalloc ( mem_heap_t * heap,
ulint n )

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

Returns
allocated, zero-filled storage in: number of bytes; if the heap is allowed to grow into the buffer pool, this must be <= MEM_MAX_ALLOC_IN_BUF
Parameters
heapin: memory heap

◆ mem_init()

UNIV_INTERN void mem_init ( ulint size)

Initializes the memory system. in: common pool size in bytes

Initializes the memory system.

Parameters
sizein: common pool size in bytes

Definition at line 149 of file mem0dbg.cc.

◆ mem_strdup()

UNIV_INLINE char * mem_strdup ( const char * str)

Duplicates a NUL-terminated string.

Returns
own: a copy of the string, must be deallocated with mem_free in: string to be copied

◆ mem_strdupl()

UNIV_INLINE char * mem_strdupl ( const char * str,
ulint len )

Makes a NUL-terminated copy of a nonterminated string.

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