/** A block of a memory heap consists of the info structure
followed by an area of memory */ typedefstruct mem_block_info_t mem_block_t;
/** A memory heap is a nonempty linear list of memory blocks */ typedef mem_block_t mem_heap_t;
struct buf_block_t;
/** Types of allocation for memory heaps: DYNAMIC means allocation from the dynamicmemorypooloftheCcompiler,BUFFERmeansallocationfromthe
buffer pool; the latter method is used for very big heaps */
#define MEM_HEAP_DYNAMIC 0/* the most common type */ #define MEM_HEAP_BUFFER 1 #define MEM_HEAP_FOR_LOCK_HEAP (MEM_HEAP_BUFFER)
/** The following start size is used for the first block in the memory heap if thesizeisnotspecified,i.e.,0isgivenastheparameterinthecallof create.Thestandardsizeisthemaximum(payload)sizeoftheblocksusedfor
allocations of small buffers. */
/** If a memory heap is allowed to grow into the buffer pool, the following
is the maximum size for a single allocated buffer: */ #define MEM_MAX_ALLOC_IN_BUF (srv_page_size - 200 + REDZONE_SIZE)
/** Space needed when allocating for a user a field of length N.
The space is allocated only in multiples of UNIV_MEM_ALIGNMENT. */ #define MEM_SPACE_NEEDED(N) UT_CALC_ALIGN((N), UNIV_MEM_ALIGNMENT)
/** Frees the space occupied by a memory heap. NOTE:Usethecorrespondingmacroinsteadofthisfunction.
@param[in] heap Heap to be freed */
UNIV_INLINE void
mem_heap_free(
mem_heap_t* heap);
/** Allocates and zero-fills n bytes of memory from a memory heap. @param[in]heapmemoryheap @param[in]nnumberofbytes;iftheheapisallowedtogrowinto thebufferpool,thismustbe<=MEM_MAX_ALLOC_IN_BUF
@return allocated, zero-filled storage */
UNIV_INLINE void*
mem_heap_zalloc(
mem_heap_t* heap,
ulint n);
/** Allocates n bytes of memory from a memory heap. @param[in]heapmemoryheap @param[in]nnumberofbytes;iftheheapisallowedtogrowinto thebufferpool,thismustbe<=MEM_MAX_ALLOC_IN_BUF
@return allocated storage */
UNIV_INLINE void*
mem_heap_alloc(
mem_heap_t* heap,
ulint n);
/** Returns a pointer to the heap top. @param[in]heapmemoryheap
@return pointer to the heap top */
UNIV_INLINE
byte*
mem_heap_get_heap_top(
mem_heap_t* heap);
/** Frees the space in a memory heap exceeding the pointer given. Thepointermusthavebeenacquiredfrommem_heap_get_heap_top. Thefirstmemoryblockoftheheapisnotfreed. @param[in]heapheapfromwhichtofree
@param[in] old_top pointer to old top of heap */
UNIV_INLINE void
mem_heap_free_heap_top(
mem_heap_t* heap,
byte* old_top);
/** Empties a memory heap. Thefirstmemoryblockoftheheapisnotfreed.
@param[in] heap heap to empty */
UNIV_INLINE void
mem_heap_empty(
mem_heap_t* heap);
/*****************************************************************//**
Returns the space in bytes occupied by a memory heap. */
UNIV_INLINE
ulint
mem_heap_get_size( /*==============*/
mem_heap_t* heap); /*!< in: heap */
/**********************************************************************//**
Duplicates a NUL-terminated string.
@return own: a copy of the string, must be deallocated with ut_free */
UNIV_INLINE char*
mem_strdup( /*=======*/ constchar* str); /*!< in: string to be copied */ /**********************************************************************//**
Makes a NUL-terminated copy of a nonterminated string.
@return own: a copy of the string, must be deallocated with ut_free */
UNIV_INLINE char*
mem_strdupl( /*========*/ constchar* str, /*!< in: string to be copied */
ulint len); /*!< in: length of str, in bytes */
/** Duplicate a block of data, allocated from a memory heap. @param[in]heapmemoryheapwherestringisallocated @param[in]datablockofdatatobecopied @param[in]lenlengthofdata,inbytes
@return own: a copy of data */ inline void*
mem_heap_dup(mem_heap_t* heap, constvoid* data, size_t len)
{
ut_ad(data || !len); return UNIV_LIKELY(data != NULL)
? memcpy(mem_heap_alloc(heap, len), data, len)
: NULL;
}
/** Duplicate a NUL-terminated string, allocated from a memory heap. @param[in]heapmemoryheapwherestringisallocated @param[in]strstringtobecopied
@return own: a copy of the string */ inline char*
mem_heap_strdup(mem_heap_t* heap, constchar* str)
{ return(static_cast<char*>(mem_heap_dup(heap, str, strlen(str) + 1)));
}
/** Duplicate a string, allocated from a memory heap. @param[in]heapmemoryheapwherestringisallocated @param[in]strstringtobecopied @param[in]lenlengthofstr,inbytes
@return own: a NUL-terminated copy of str */ inline char*
mem_heap_strdupl(mem_heap_t* heap, constchar* str, size_t len)
{ char* s = static_cast<char*>(mem_heap_alloc(heap, len + 1));
s[len] = 0; return(static_cast<char*>(memcpy(s, str, len)));
}
/**********************************************************************//**
Concatenate two strings andreturn the result, using a memory heap.
@return own: the result */ char*
mem_heap_strcat( /*============*/
mem_heap_t* heap, /*!< in: memory heap where string is allocated */ constchar* s1, /*!< in: string 1 */ constchar* s2); /*!< in: string 2 */
/****************************************************************//**
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).
@return heap-allocated formatted string */ char*
mem_heap_printf( /*============*/
mem_heap_t* heap, /*!< in: memory heap */ constchar* format, /*!< in: format string */
...) MY_ATTRIBUTE ((format (printf, 2, 3)));
#ifdef UNIV_DEBUG /** Validates the contents of a memory heap. Assertsthatthememoryheapisconsistent
@param[in] heap Memory heap to validate */ void
mem_heap_validate( const mem_heap_t* heap);
/** The info structure stored at the beginning of a heap block */ struct mem_block_info_t { #ifdef UNIV_DEBUG char file_name[8];/* file name where the mem heap was created */ unsigned line; /*!< line number where the mem heap was created */ #endif/* UNIV_DEBUG */
UT_LIST_BASE_NODE_T(mem_block_t) base; /* In the first block in the thelistthisisthebasenodeofthelistofblocks;
in subsequent blocks this is undefined */
UT_LIST_NODE_T(mem_block_t) list; /* This contains pointers to next andprevinthelist.Thefirstblockallocated totheheapisalsothefirstblockinthislist,
though it also contains the base node of the list. */
ulint len; /*!< physical length of this block in bytes */
ulint total_size; /*!< physical length in bytes of all blocks intheheap.Thisisdefinedonlyinthebase
node and is set to ULINT_UNDEFINED in others. */
ulint type; /*!< type of heap: MEM_HEAP_DYNAMIC, or
MEM_HEAP_BUFFER */
ulint free; /*!< offset in bytes of the first free position for
user data in the block */
ulint start; /*!< the value of the struct field 'free' at the
creation of the block */
buf_block_t* buf_block; /* if this block has been allocated from the buffer pool,thiscontainsthebuf_block_thandle;
otherwise, this is NULL */
};
/* Header size for a memory heap block */ #define MEM_BLOCK_HEADER_SIZE UT_CALC_ALIGN(sizeof(mem_block_info_t),\
UNIV_MEM_ALIGNMENT)
#include"mem0mem.inl" #endif
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.