InnoDB Plugin  1.0
Data Structures | Macros | Typedefs | Functions
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 "mem0mem.ic"
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.

Data Structures

struct  mem_block_info_t

Macros

#define MEM_HEAP_DYNAMIC   0 /* the most common type */
#define MEM_HEAP_BUFFER   1
#define MEM_HEAP_BTR_SEARCH
#define MEM_HEAP_FOR_BTR_SEARCH   (MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER)
#define MEM_HEAP_FOR_PAGE_HASH   (MEM_HEAP_DYNAMIC)
#define MEM_HEAP_FOR_RECV_SYS   (MEM_HEAP_BUFFER)
#define MEM_HEAP_FOR_LOCK_HEAP   (MEM_HEAP_BUFFER)
#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_typed(N, T)
#define mem_heap_free(heap)
#define mem_zalloc(N)   memset(mem_alloc(N), 0, (N))
#define mem_alloc(N)   mem_alloc_func((N), __FILE__, __LINE__, NULL)
#define mem_alloc2(N, S)   mem_alloc_func((N), __FILE__, __LINE__, (S))
#define mem_free(PTR)   mem_free_func((PTR), __FILE__, __LINE__)
#define MEM_BLOCK_MAGIC_N   764741555
#define MEM_FREED_BLOCK_MAGIC_N   547711122
#define MEM_BLOCK_HEADER_SIZE

Typedefs

typedef struct 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_tmem_heap_create_func (ulint n, const char *file_name, ulint line, ulint type)
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, const char *file_name, ulint line, ulint *size)
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,...)))

Detailed Description

The memory management

Created 6/9/1994 Heikki Tuuri

Macro Definition Documentation

#define MEM_BLOCK_HEADER_SIZE
#define mem_free (   PTR)    mem_free_func((PTR), __FILE__, __LINE__)

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

#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 it's NULL, the memory
allocation functions can return
NULL. */
#define mem_heap_create (   N)
Value:
(N), __FILE__, __LINE__, MEM_HEAP_DYNAMIC)

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

#define mem_heap_create_typed (   N,
 
)
Value:
(N), __FILE__, __LINE__, (T))

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

#define mem_heap_free (   heap)
Value:
(heap), __FILE__, __LINE__)

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

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

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

Function Documentation

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

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 out: allocated size in bytes, or NULL

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
Parameters
nin: desired number of bytes
file_namein: file name where created
linein: line where created
sizeout: allocated size in bytes, or NULL
UNIV_INTERN void mem_close ( void  )

Closes the memory system.

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

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

Parameters
ptrin, own: buffer to be freed
file_namein: file name where created
linein: line where created
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

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)
Parameters
heapin: memory heap
nin: number of bytes; if the heap is allowed to grow into the buffer pool, this must be <= MEM_MAX_ALLOC_IN_BUF
UNIV_INLINE mem_heap_t* mem_heap_create_func ( ulint  n,
const char *  file_name,
ulint  line,
ulint  type 
)

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: heap type

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

Returns
own: memory heap, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps)
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
file_namein: file name where created
linein: line where created
typein: heap type
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
Parameters
heapin: memory heap where copy is allocated
datain: data to be copied
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

Empties a memory heap. The first memory block of the heap is not freed.

Parameters
heapin: heap to empty
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
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

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
heapin: heap from which to free
old_topin: pointer to old top of heap
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

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

Returns a pointer to the heap top.

Returns
pointer to the heap top
Parameters
heapin: memory heap
UNIV_INLINE ulint mem_heap_get_size ( mem_heap_t heap)

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

Returns the space in bytes occupied by a memory heap.

Parameters
heapin: heap
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

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
Parameters
heapin: memory heap
nin: size of the topmost element
UNIV_INTERN 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
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
Parameters
heapin: memory heap where string is allocated
s1in: string 1
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
Parameters
heapin: memory heap where string is allocated
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

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

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

Returns
allocated, zero-filled storage
Parameters
heapin: memory heap
nin: number of bytes; if the heap is allowed to grow into the buffer pool, this must be <= MEM_MAX_ALLOC_IN_BUF
UNIV_INTERN void mem_init ( ulint  size)

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

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

Duplicates a NUL-terminated string.

Returns
own: a copy of the string, must be deallocated with mem_free
Parameters
strin: string to be copied
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

Makes a NUL-terminated copy of a nonterminated string.

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