#define OUT_OF_MEMORY_MSG \ "Check if you should increase the swap file or ulimits of your" \ " operating system. Note that on most 32-bit computers the process" \ " memory space is limited to 2 GB or 4 GB."
/** The total amount of memory currently allocated from the operating
system with allocate_large() */ extern Atomic_counter<ulint> os_total_large_mem_allocated;
/** Maximum number of retries to allocate memory. */ externconst size_t alloc_max_retries;
/** A structure that holds the necessary data for performance schema accounting.Anobjectofthistypeisputinfrontofeachallocatedblock ofmemorywhenallocationisdonebyut_allocator::allocate().Thisis becausethedataisneededevenwhenfreeingthememory.Usersof ut_allocator::allocate_large()areresponsibleformaintainingthis
themselves. */ struct ut_new_pfx_t {
#ifdef UNIV_PFS_MEMORY
/** Performance schema key. Assigned to a name at startup via PSI_MEMORY_CALL(register_memory)()andlaterusedforaccounting allocationsanddeallocationswith PSI_MEMORY_CALL(memory_alloc)(key,size,owner)and
PSI_MEMORY_CALL(memory_free)(key, size, owner). */
PSI_memory_key m_key;
/** Size of the allocated block in bytes, including this prepended auxstructure(forut_allocator::allocate()).ForexampleifInnoDB coderequeststoallocate100bytes,andsizeof(ut_new_pfx_t)is16, then116bytesareallocatedintotalandm_sizewillbe116. ut_allocator::allocate_large()doesnotprependthisstructtothe allocatedblockanditsusersareresponsibleformaintainingit
and passing it later to ut_allocator::deallocate_large(). */
size_t m_size; #if SIZEOF_VOIDP == 4 /** Pad the header size to a multiple of 64 bits on 32-bit systems,
so that the payload will be aligned to 64 bits. */
size_t pad; #endif
};
/** Return the maximum number of objects that can be allocated by
this allocator. */
size_type
max_size() const
{ const size_type s_max = std::numeric_limits<size_type>::max();
if (pfx_new == NULL) {
ib::fatal_or_error(oom_fatal)
<< "Cannot reallocate " << total_bytes
<< " bytes of memory after "
<< alloc_max_retries << " retries over "
<< alloc_max_retries << " seconds. OS error: "
<< strerror(errno) << " (" << errno << "). "
<< OUT_OF_MEMORY_MSG; return(NULL);
}
/* pfx_new still contains the description of the old block
that was presumably freed by realloc(). */
deallocate_trace(pfx_new);
/* pfx_new is set here to describe the new block. */
allocate_trace(total_bytes, autoevent_idx, pfx_new);
return(reinterpret_cast<pointer>(pfx_new + 1));
}
/** Allocate, trace the allocation and construct 'n_elements' objects oftype'T'.Iftheallocationfailsorifsomeoftheconstructors throwsanexception,thenthismethodwillreturnNULL.Itdoesnot throwexceptions.Aftersuccessfullcompletionthereturnedpointer mustbepassedtodelete_array()whennolongerneeded. @param[in]n_elementsnumberofelementstoallocate @param[in]filefilenameofthecaller
@return pointer to the first allocated object or NULL */
pointer
new_array(
size_type n_elements,
uint32_t autoevent_idx
)
{
T* p = allocate(n_elements, NULL, autoevent_idx, false, false);
if (p == NULL) { return(NULL);
}
T* first = p;
size_type i;
try { for (i = 0; i < n_elements; i++) { new(p) T;
++p;
}
} catch (...) { for (size_type j = 0; j < i; j++) {
--p;
p->~T();
}
deallocate(first);
throw;
}
return(first);
}
/** Destroy, deallocate and trace the deallocation of an array created bynew_array().
@param[in,out] ptr pointer to the first object in the array */ void
delete_array(
T* ptr)
{ if (ptr == NULL) { return;
}
for (size_type i = 0; i < n_elements; i++) {
p->~T();
--p;
}
deallocate(ptr);
}
#endif/* UNIV_PFS_MEMORY */
/** Allocate a large chunk of memory that can hold 'n_elements' objectsoftype'T'andtracetheallocation. @param[in]n_elementsnumberofelements @param[in]dontdumpiftrue,advisetheOSisnottocore dumpthismemory. @param[out]pfxstorageforthedescriptionofthe allocatedmemory.Thecallermustprovidespaceforthisoneandkeep ituntilthememoryisnolongerneededandthenpassitto deallocate_large().
@return pointer to the allocated memory or NULL */
pointer
allocate_large(
size_type n_elements,
ut_new_pfx_t* pfx, bool dontdump = false)
{ if (n_elements == 0 || n_elements > max_size()) { return(NULL);
}
/** Compare two allocators of the same type. AslongasthetypeofA1andA2isthesame,amemoryallocatedbyA1
could be freed by A2 even if the pfs mem key is different. */ template <typename T> inline bool operator==(const ut_allocator<T>&, const ut_allocator<T>&) { return(true); }
/** Compare two allocators of the same type. */ template <typename T> inline bool operator!=( const ut_allocator<T>& lhs, const ut_allocator<T>& rhs)
{ return(!(lhs == rhs));
}
Weirdlookinglambdaisusedtoforcetheevaluationatthecompiletime.
*/ #define AUTOEVENT_IDX []()\
{\
constexpr auto idx = cexpr_lookup_auto_event_name(cexpr_basename(__FILE__)); \
static_assert(idx != INVALID_AUTOEVENT_IDX, "auto_event_names contains no entry for " __FILE__);\ return idx; \
}()
/** Allocate, trace the allocation and construct an object. Usethismacroinsteadof'new'withinInnoDB. Forexample:insteadof Foo*f=newFoo(args); use: Foo*f=UT_NEW(Foo(args),mem_key_some); Uponfailuretoallocatethememory,thismacromayreturnNULL.It willnotthrowexceptions.Aftersuccessfullallocationthereturned pointermustbepassedtoUT_DELETE()whennolongerneeded. @param[in]expranyexpressionthatcouldfollow"new" @param[in]keyperformanceschemamemorytracingkey
@return pointer to the created object or NULL */ #define UT_NEW(expr, key) \ /* Placement new will return NULL and not attempt to construct an objectifthepassedinpointerisNULL,e.g.ifallocate()has
failed to allocate memory and has returned NULL. */ \
::new(ut_allocator<byte>(key).allocate( \ sizeof expr, NULL, AUTOEVENT_IDX, false, false)) expr
/** Allocate, trace the allocation and construct an object. Usethismacroinsteadof'new'withinInnoDBandinsteadofUT_NEW() whencreatingadedicatedmemorykeyisnotfeasible. Forexample:insteadof Foo*f=newFoo(args); use: Foo*f=UT_NEW_NOKEY(Foo(args)); Uponfailuretoallocatethememory,thismacromayreturnNULL.It willnotthrowexceptions.Aftersuccessfullallocationthereturned pointermustbepassedtoUT_DELETE()whennolongerneeded. @param[in]expranyexpressionthatcouldfollow"new"
@return pointer to the created object or NULL */ #define UT_NEW_NOKEY(expr) UT_NEW(expr, PSI_NOT_INSTRUMENTED)
/** Destroy, deallocate and trace the deallocation of an object created by UT_NEW()orUT_NEW_NOKEY(). Wecan'tinstantiateut_allocatorwithouthavingthetypeoftheobject,thus
we redirect this to a templated function. */ #define UT_DELETE(ptr) ut_delete(ptr)
/** Destroy and account object created by UT_NEW() or UT_NEW_NOKEY().
@param[in,out] ptr pointer to the object */ template <typename T> inline void
ut_delete(
T* ptr)
{ if (ptr == NULL) { return;
}
/** Allocate and account 'n_elements' objects of type 'type'. UsethismacrotoallocatememorywithinInnoDBinsteadof'new[]'. ThereturnedpointermustbepassedtoUT_DELETE_ARRAY(). @param[in]typetypeofobjectsbeingcreated @param[in]n_elementsnumberofobjectstocreate @param[in]keyperformanceschemamemorytracingkey
@return pointer to the first allocated object or NULL */ #define UT_NEW_ARRAY(type, n_elements, key) \
ut_allocator<type>(key).new_array(n_elements, AUTOEVENT_IDX)
/** Allocate and account 'n_elements' objects of type 'type'. UsethismacrotoallocatememorywithinInnoDBinsteadof'new[]'and insteadofUT_NEW_ARRAY()whenitisnotfeasibletocreateadedicatedkey. @param[in]typetypeofobjectsbeingcreated @param[in]n_elementsnumberofobjectstocreate
@return pointer to the first allocated object or NULL */ #define UT_NEW_ARRAY_NOKEY(type, n_elements) \
UT_NEW_ARRAY(type, n_elements, PSI_NOT_INSTRUMENTED)
/** Destroy, deallocate and trace the deallocation of an array created by UT_NEW_ARRAY()orUT_NEW_ARRAY_NOKEY(). Wecan'tinstantiateut_allocatorwithouthavingthetypeoftheobject,thus
we redirect this to a templated function. */ #define UT_DELETE_ARRAY(ptr) ut_delete_array(ptr)
/** Destroy and account objects created by UT_NEW_ARRAY() or UT_NEW_ARRAY_NOKEY().
@param[in,out] ptr pointer to the first object in the array */ template <typename T> inline void
ut_delete_array(
T* ptr)
{
ut_allocator<T>().delete_array(ptr);
}
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.