Drizzled Public API Documentation

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"

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)   memset(mem_alloc(N), 0, (N))
 
#define mem_alloc(N)   mem_alloc_func((N), NULL, __FILE__, __LINE__)
 
#define mem_alloc2(N, S)   mem_alloc_func((N), (S), __FILE__, __LINE__)
 
#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_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_tmem_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

#define MEM_BLOCK_HEADER_SIZE
Value:
UNIV_MEM_ALIGNMENT)

Definition at line 395 of file mem0mem.h.

#define mem_free (   PTR)    mem_free_func((PTR), __FILE__, __LINE__)
#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.

#define mem_heap_create (   N)
Value:
(N), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)

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

Definition at line 97 of file mem0mem.h.

Referenced by btr_compress(), btr_cur_optimistic_update(), btr_cur_parse_update_in_place(), btr_estimate_number_of_different_key_vals(), btr_page_split_and_insert(), btr_pcur_restore_position_func(), btr_root_raise_and_insert(), dict_boot(), dict_create_foreign_constraints(), dict_get_first_table_name_in_db(), dict_load_foreigns(), dict_load_sys_table(), dict_load_table(), dict_load_table_on_id(), dict_mem_foreign_create(), dict_mem_index_create(), dict_mem_table_create(), dict_print(), dtuple_convert_big_rec(), ibuf_merge_or_delete_for_page(), ind_create_graph_create(), ins_node_create(), lock_move_reorganize_page(), page_validate(), pars_info_create(), pars_sql(), read_cursor_view_create_for_mysql(), ha_innobase::records_in_range(), recv_sys_init(), row_check_index_for_mysql(), row_create_index_for_mysql(), row_create_prebuilt(), row_create_table_for_mysql(), row_drop_table_for_mysql(), row_get_clust_rec(), row_merge_create_temporary_table(), row_merge_lock_table(), row_mysql_drop_temp_tables(), row_purge_node_create(), row_rename_table_for_mysql(), row_truncate_table_for_mysql(), row_undo_node_create(), row_vers_build_for_consistent_read(), row_vers_build_for_semi_consistent_read(), row_vers_impl_x_locked_off_kernel(), row_vers_old_has_index_entry(), tab_create_graph_create(), trx_create(), trx_general_rollback_for_mysql(), trx_purge_sys_create(), trx_roll_graph_build(), trx_undo_arr_create(), and upd_node_create().

#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 109 of file mem0mem.h.

Referenced by ha_create_func().

#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 103 of file mem0mem.h.

Referenced by recv_sys_init(), and trx_create().

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

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

Definition at line 117 of file mem0mem.h.

Referenced by btr_compress(), btr_cur_open_at_rnd_pos_func(), btr_cur_optimistic_update(), btr_cur_parse_del_mark_set_clust_rec(), btr_cur_parse_update_in_place(), btr_cur_search_to_nth_level(), btr_cur_update_in_place(), btr_estimate_number_of_different_key_vals(), btr_index_rec_validate(), btr_page_split_and_insert(), btr_pcur_restore_position_func(), btr_root_raise_and_insert(), btr_search_drop_page_hash_index(), btr_search_sys_free(), btr_search_update_hash_on_delete(), btr_search_update_hash_on_insert(), dict_boot(), dict_create_foreign_constraints(), dict_foreign_add_to_cache(), dict_get_first_table_name_in_db(), dict_load_foreigns(), dict_load_sys_table(), dict_load_table(), dict_load_table_on_id(), dict_mem_index_free(), dict_mem_table_free(), dict_print(), dtuple_convert_back_big_rec(), dtuple_convert_big_rec(), ha_clear(), ibuf_merge_or_delete_for_page(), lock_clust_rec_read_check_and_lock_alt(), lock_move_reorganize_page(), lock_rec_insert_check_and_lock(), lock_rec_print(), lock_sec_rec_modify_check_and_lock(), page_copy_rec_list_end_no_locks(), page_copy_rec_list_end_to_created_page(), page_copy_rec_list_start(), page_cur_insert_rec_low(), page_cur_insert_rec_zip(), page_cur_parse_delete_rec(), page_cur_parse_insert_rec(), page_cur_search_with_match(), page_delete_rec_list_end(), page_delete_rec_list_start(), page_print_list(), page_validate(), pars_info_free(), que_graph_free(), que_graph_free_recursive(), read_cursor_view_close_for_mysql(), rec_convert_dtuple_to_rec(), rec_print(), ha_innobase::records_in_range(), recv_sys_close(), recv_sys_mem_free(), row_build(), row_build_row_ref(), row_build_row_ref_in_tuple(), row_check_index_for_mysql(), row_drop_table_for_mysql(), row_get_clust_rec(), row_ins_check_foreign_constraint(), row_merge_create_temporary_table(), row_mysql_drop_temp_tables(), row_mysql_prebuilt_free_blob_heap(), row_prebuilt_free(), row_rename_table_for_mysql(), row_search_for_mysql(), row_truncate_table_for_mysql(), row_undo_search_clust_to_pcur(), row_unlock_for_mysql(), row_vers_build_for_consistent_read(), row_vers_build_for_semi_consistent_read(), row_vers_impl_x_locked_off_kernel(), row_vers_old_has_index_entry(), sel_node_free_private(), trx_free(), trx_general_rollback_for_mysql(), trx_purge_sys_close(), trx_undo_arr_free(), and trx_undo_report_row_operation().

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

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

Definition at line 225 of file mem0mem.h.

Referenced by buf_pool_init(), buf_print_io(), fil_init(), srv_init(), trx_purge_sys_create(), and trx_sys_init_at_db_start().

Function Documentation

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
UNIV_INTERN void mem_close ( void  )

Closes the memory system.

Definition at line 186 of file mem0dbg.cc.

References mem_close(), mem_comm_pool, and mem_pool_free().

Referenced by innobase_shutdown_for_mysql(), and mem_close().

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

Referenced by btr_push_update_extern_fields(), btr_search_info_create(), commit_node_create(), dict_index_add_to_cache(), dict_index_build_node_ptr(), dict_mem_foreign_table_name_lookup_set(), dict_mem_referenced_table_name_lookup_set(), dict_mem_table_create(), dict_process_sys_fields_rec(), dict_process_sys_indexes_rec(), dict_table_rename_in_cache(), dtuple_convert_big_rec(), ha_insert_for_fold_func(), ha_storage_put_memlim(), ib_list_add_after(), ib_list_create_heap(), ib_vector_create(), ib_vector_push(), ind_create_graph_create(), ins_node_create(), mem_heap_dup(), mem_heap_strcat(), opt_search_plan(), pars_assignment_statement(), pars_column_assignment(), pars_elsif_element(), pars_exit_statement(), pars_fetch_statement(), pars_for_statement(), pars_if_statement(), pars_info_add_function(), pars_info_add_id(), pars_info_add_int4_literal(), pars_info_add_literal(), pars_info_add_ull_literal(), pars_info_create(), pars_open_statement(), pars_order_by(), pars_procedure_definition(), pars_return_statement(), pars_row_printf_statement(), pars_while_statement(), que_fork_create(), que_thr_create(), read_cursor_view_create_for_mysql(), rec_get_offsets_func(), roll_node_create(), row_build(), row_build_row_ref(), row_ext_create(), row_purge_node_create(), row_rec_to_index_entry(), row_truncate_table_for_mysql(), row_undo_node_create(), row_upd_replace(), row_vers_build_for_consistent_read(), row_vers_build_for_semi_consistent_read(), sel_node_create(), sym_tab_add_bound_id(), sym_tab_add_bound_lit(), sym_tab_add_id(), sym_tab_add_int_lit(), sym_tab_add_null_lit(), sym_tab_add_str_lit(), sym_tab_create(), tab_create_graph_create(), trx_undo_arr_create(), trx_undo_prev_version_build(), trx_undo_update_rec_get_update(), and upd_node_create().

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

Referenced by rec_get_offsets_func().

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 120 of file mem0mem.cc.

References mem_heap_alloc(), and mem_heap_dup().

Referenced by mem_heap_dup(), mem_heap_strdup(), pars_sql(), rec_copy_prefix_to_dtuple(), row_check_index_for_mysql(), and row_upd_index_parse().

UNIV_INLINE void mem_heap_empty ( mem_heap_t heap)
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

Parameters
heapin: heap from which to free
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
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
UNIV_INLINE ulint mem_heap_get_size ( mem_heap_t heap)

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

Referenced by dict_index_add_to_cache(), dict_index_remove_from_cache(), dict_table_add_to_cache(), dict_table_remove_from_cache(), recv_scan_log_recs(), and trx_print().

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
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
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 134 of file mem0mem.cc.

References mem_heap_alloc(), and mem_heap_strcat().

Referenced by mem_heap_strcat().

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 107 of file mem0mem.cc.

References mem_heap_dup(), and mem_heap_strdup().

Referenced by create_table_def(), dict_table_rename_in_cache(), mem_heap_strdup(), row_drop_table_for_mysql(), and sym_tab_add_bound_id().

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

Referenced by dict_load_column_low(), dict_load_field_low(), dict_load_foreigns(), dict_load_index_low(), dict_load_table_on_id(), dict_process_sys_foreign_col_rec(), dict_process_sys_foreign_rec(), dict_process_sys_tables_rec(), row_mysql_drop_temp_tables(), row_rename_table_for_mysql(), and sym_tab_add_id().

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

Referenced by btr_estimate_number_of_different_key_vals(), dict_index_add_to_cache(), dict_mem_foreign_create(), dict_mem_index_create(), dict_mem_table_add_col(), dict_mem_table_create(), page_validate(), and row_create_prebuilt().

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.

References mem_comm_pool, mem_init(), mem_pool_create(), ut_a, and UT_LIST_INIT.

Referenced by mem_init(), and srv_general_init().

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

Referenced by dict_table_rename_in_cache(), fil_delete_tablespace(), fil_node_create(), fil_rename_tablespace(), fil_space_create(), os_file_dirname(), row_create_index_for_mysql(), and trx_savepoint_for_mysql().

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

Referenced by dict_check_tablespaces_and_store_max_id(), dict_get_first_table_name_in_db(), and os_file_dirname().