#include "univ.i"
#include "ut0mem.h"
#include "ut0byte.h"
#include "ut0rnd.h"
#include "sync0sync.h"
#include "ut0lst.h"
#include "mach0data.h"
#include "mem0dbg.h"
Go to the source code of this file.
|
| 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 |
The memory management
Created 6/9/1994 Heikki Tuuri
Definition in file mem0mem.h.
◆ mem0mem_h
◆ mem_alloc
Value:
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 ) |
◆ MEM_BLOCK_HEADER_SIZE
| #define MEM_BLOCK_HEADER_SIZE |
Value:
UNIV_MEM_ALIGNMENT)
#define ut_calc_align(n, m)
Definition at line 389 of file mem0mem.h.
◆ MEM_BLOCK_MAGIC_N
| #define MEM_BLOCK_MAGIC_N 764741555 |
◆ MEM_BLOCK_STANDARD_SIZE
| #define MEM_BLOCK_STANDARD_SIZE (UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF) |
◆ MEM_BLOCK_START_SIZE
| #define MEM_BLOCK_START_SIZE 64 |
◆ mem_free
Value:
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 |
◆ MEM_HEAP_BTR_SEARCH
| #define MEM_HEAP_BTR_SEARCH |
◆ MEM_HEAP_BUFFER
| #define MEM_HEAP_BUFFER 1 |
◆ 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 */ |
◆ 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) |
◆ mem_zalloc
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.
◆ mem_block_info_t
◆ mem_block_t
| typedef mem_block_info_t mem_block_t |
◆ mem_heap_t
| typedef mem_block_t mem_heap_t |
◆ 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
-
| n | in: requested size in bytes |
| size | out: allocated size in bytes, or NULL |
| file_name | in: 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
-
| ptr | in, own: buffer to be freed |
| file_name | in: 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
-
◆ 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
-
| n | in: 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 |
| type | in: heap type |
| file_name | in: 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
-
| heap | in: memory heap where copy is allocated |
| data | in: data to be copied |
| len | in: 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
-
| heap | in, own: heap to be freed |
| file_name | in: 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
-
| heap | in: 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
-
◆ 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
-
◆ 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
-
| heap | in: memory heap |
| format | in: 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
-
| heap | in: memory heap where string is allocated |
| s1 | in: string 1 |
| s2 | in: 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
-
| heap | in: memory heap where string is allocated |
| str | in: 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
-
| heap | in: memory heap where string is allocated |
| str | in: 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
-
◆ mem_init()
| UNIV_INTERN void mem_init |
( |
ulint | size | ) |
|
Initializes the memory system. in: common pool size in bytes
Initializes the memory system.
- Parameters
-
| size | in: 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
-
| str | in: string to be copied |