本文整理汇总了C++中MemoryContextIsValid函数的典型用法代码示例。如果您正苦于以下问题:C++ MemoryContextIsValid函数的具体用法?C++ MemoryContextIsValid怎么用?C++ MemoryContextIsValid使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MemoryContextIsValid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: repalloc_huge
/*
* repalloc_huge
* Adjust the size of a previously allocated chunk, permitting a large
* value. The previous allocation need not have been "huge".
*/
void *
repalloc_huge(void *pointer, Size size)
{
MemoryContext context;
void *ret;
if (!AllocHugeSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %zu", size);
/*
* Try to detect bogus pointers handed to us, poorly though we can.
* Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
* allocated chunk.
*/
Assert(pointer != NULL);
Assert(pointer == (void *) MAXALIGN(pointer));
/*
* OK, it's probably safe to look at the chunk header.
*/
context = ((StandardChunkHeader *)
((char *) pointer - STANDARDCHUNKHEADERSIZE))->context;
AssertArg(MemoryContextIsValid(context));
AssertNotInCriticalSection(context);
/* isReset must be false already */
Assert(!context->isReset);
ret = (*context->methods->realloc) (context, pointer, size);
VALGRIND_MEMPOOL_CHANGE(context, pointer, ret, size);
return ret;
}
示例2: MemoryContextDelete
/*
* MemoryContextDelete
* Delete a context and its descendants, and release all space
* allocated therein.
*
* The type-specific delete routine removes all subsidiary storage
* for the context, but we have to delete the context node itself,
* as well as recurse to get the children. We must also delink the
* node from its parent, if it has one.
*/
void
MemoryContextDelete(MemoryContext context)
{
AssertArg(MemoryContextIsValid(context));
/* We had better not be deleting TopMemoryContext ... */
Assert(context != TopMemoryContext);
/* And not CurrentMemoryContext, either */
Assert(context != CurrentMemoryContext);
MemoryContextDeleteChildren(context);
/*
* It's not entirely clear whether 'tis better to do this before or after
* delinking the context; but an error in a callback will likely result in
* leaking the whole context (if it's not a root context) if we do it
* after, so let's do it before.
*/
MemoryContextCallResetCallbacks(context);
/*
* We delink the context from its parent before deleting it, so that if
* there's an error we won't have deleted/busted contexts still attached
* to the context tree. Better a leak than a crash.
*/
MemoryContextSetParent(context, NULL);
(*context->methods->delete_context) (context);
VALGRIND_DESTROY_MEMPOOL(context);
pfree(context);
}
示例3: MemoryContextAllowInCriticalSection
/*
* MemoryContextAllowInCriticalSection
* Allow/disallow allocations in this memory context within a critical
* section.
*
* Normally, memory allocations are not allowed within a critical section,
* because a failure would lead to PANIC. There are a few exceptions to
* that, like allocations related to debugging code that is not supposed to
* be enabled in production. This function can be used to exempt specific
* memory contexts from the assertion in palloc().
*/
void
MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
{
AssertArg(MemoryContextIsValid(context));
context->allowInCritSection = allow;
}
示例4: MemoryContextGetParent
/*
* MemoryContextGetParent
* Get the parent context (if any) of the specified context
*/
MemoryContext
MemoryContextGetParent(MemoryContext context)
{
AssertArg(MemoryContextIsValid(context));
return context->parent;
}
示例5: MemoryContextStats
/*
* MemoryContextStats
* Prints the usage details of a context.
*
* Parameters:
* context: the context of interest.
*/
void
MemoryContextStats(MemoryContext context)
{
char* name;
char namebuf[MAX_CONTEXT_NAME_SIZE];
AssertArg(MemoryContextIsValid(context));
name = MemoryContextName(context, NULL, namebuf, sizeof(namebuf));
write_stderr("pid %d: Memory statistics for %s/\n", MyProcPid, name);
write_stderr("context: occurrences_count, currently_allocated, currently_available, total_allocated, total_freed, name\n");
uint64 nBlocks = 0;
uint64 nChunks = 0;
uint64 currentAvailable = 0;
uint64 allAllocated = 0;
uint64 allFreed = 0;
uint64 maxHeld = 0;
int namebufsize = sizeof(namebuf);
/* Get the root context's stat and pass it to the MemoryContextStats_recur for printing */
(*context->methods.stats)(context, &nBlocks, &nChunks, ¤tAvailable, &allAllocated, &allFreed, &maxHeld);
name = MemoryContextName(context, context, namebuf, namebufsize);
MemoryContextStats_recur(context, context, name, namebuf, namebufsize, nBlocks, nChunks,
currentAvailable, allAllocated, allFreed, maxHeld);
}
示例6: MemoryContextAllocZeroAlignedImpl
/*
* MemoryContextAllocZeroAligned
* MemoryContextAllocZero where length is suitable for MemSetLoop
*
* This might seem overly specialized, but it's not because newNode()
* is so often called with compile-time-constant sizes.
*/
void *
MemoryContextAllocZeroAlignedImpl(MemoryContext context, Size size, const char* sfile, const char *sfunc, int sline)
{
void *ret;
#ifdef PGTRACE_ENABLED
StandardChunkHeader *header;
#endif
AssertArg(MemoryContextIsValid(context));
#ifdef CDB_PALLOC_CALLER_ID
context->callerFile = sfile;
context->callerLine = sline;
#endif
if (!AllocSizeIsValid(size))
MemoryContextError(ERRCODE_INTERNAL_ERROR,
context, CDB_MCXT_WHERE(context),
"invalid memory alloc request size %lu",
(unsigned long)size);
ret = (*context->methods.alloc) (context, size);
MemSetLoop(ret, 0, size);
#ifdef PGTRACE_ENABLED
header = (StandardChunkHeader *)
((char *) ret - STANDARDCHUNKHEADERSIZE);
PG_TRACE5(memctxt__alloc, size, header->size, 0, 0, (long) context->name);
#endif
return ret;
}
示例7: MemoryContextAllocZeroAligned
/*
* MemoryContextAllocZeroAligned
* MemoryContextAllocZero where length is suitable for MemSetLoop
*
* This might seem overly specialized, but it's not because newNode()
* is so often called with compile-time-constant sizes.
*/
void *
MemoryContextAllocZeroAligned(MemoryContext context, Size size)
{
void *ret;
AssertArg(MemoryContextIsValid(context));
AssertNotInCriticalSection(context);
if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %zu", size);
context->isReset = false;
ret = (*context->methods->alloc) (context, size);
if (ret == NULL)
{
MemoryContextStats(TopMemoryContext);
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed on request of size %zu.", size)));
}
VALGRIND_MEMPOOL_ALLOC(context, ret, size);
MemSetLoop(ret, 0, size);
return ret;
}
示例8: MemoryContextAllocExtended
/*
* MemoryContextAllocExtended
* Allocate space within the specified context using the given flags.
*/
void *
MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
{
void *ret;
AssertArg(MemoryContextIsValid(context));
AssertNotInCriticalSection(context);
if (((flags & MCXT_ALLOC_HUGE) != 0 && !AllocHugeSizeIsValid(size)) ||
((flags & MCXT_ALLOC_HUGE) == 0 && !AllocSizeIsValid(size)))
elog(ERROR, "invalid memory alloc request size %zu", size);
context->isReset = false;
ret = (*context->methods->alloc) (context, size);
if (ret == NULL)
{
if ((flags & MCXT_ALLOC_NO_OOM) == 0)
{
MemoryContextStats(TopMemoryContext);
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed on request of size %zu.", size)));
}
return NULL;
}
VALGRIND_MEMPOOL_ALLOC(context, ret, size);
if ((flags & MCXT_ALLOC_ZERO) != 0)
MemSetAligned(ret, 0, size);
return ret;
}
示例9: repalloc
/*
* repalloc
* Adjust the size of a previously allocated chunk.
*/
void *
repalloc(void *pointer, Size size)
{
StandardChunkHeader *header;
/*
* Try to detect bogus pointers handed to us, poorly though we can.
* Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
* allocated chunk.
*/
Assert(pointer != NULL);
Assert(pointer == (void *) MAXALIGN(pointer));
/*
* OK, it's probably safe to look at the chunk header.
*/
header = (StandardChunkHeader *)
((char *) pointer - STANDARDCHUNKHEADERSIZE);
AssertArg(MemoryContextIsValid(header->context));
if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu",
(unsigned long) size);
/* isReset must be false already */
Assert(!header->context->isReset);
return (*header->context->methods->realloc) (header->context,
pointer, size);
}
示例10: palloc0
void *
palloc0(Size size)
{
/* duplicates MemoryContextAllocZero to avoid increased overhead */
void *ret;
AssertArg(MemoryContextIsValid(CurrentMemoryContext));
AssertNotInCriticalSection(CurrentMemoryContext);
if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %zu", size);
CurrentMemoryContext->isReset = false;
ret = (*CurrentMemoryContext->methods->alloc) (CurrentMemoryContext, size);
if (ret == NULL)
{
MemoryContextStats(TopMemoryContext);
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed on request of size %zu.", size)));
}
VALGRIND_MEMPOOL_ALLOC(CurrentMemoryContext, ret, size);
MemSetAligned(ret, 0, size);
return ret;
}
示例11: MemoryContextResetAndDeleteChildren
/*
* MemoryContextResetAndDeleteChildren
* Release all space allocated within a context and delete all
* its descendants.
*
* This is a common combination case where we want to preserve the
* specific context but get rid of absolutely everything under it.
*/
void
MemoryContextResetAndDeleteChildren(MemoryContext context)
{
AssertArg(MemoryContextIsValid(context));
MemoryContextDeleteChildren(context);
MemoryContextReset(context);
}
示例12: MemoryContextResetAndDeleteChildren
/*
* MemoryContextResetAndDeleteChildren
* Release all space allocated within a context and delete all
* its descendants.
*
* This is a common combination case where we want to preserve the
* specific context but get rid of absolutely everything under it.
*/
void
MemoryContextResetAndDeleteChildren(MemoryContext context)
{
AssertArg(MemoryContextIsValid(context));
MemoryContextDeleteChildren(context);
(*context->methods.reset) (context);
}
示例13: MemoryContextSetParent
/*
* MemoryContextSetParent
* Change a context to belong to a new parent (or no parent).
*
* We provide this as an API function because it is sometimes useful to
* change a context's lifespan after creation. For example, a context
* might be created underneath a transient context, filled with data,
* and then reparented underneath CacheMemoryContext to make it long-lived.
* In this way no special effort is needed to get rid of the context in case
* a failure occurs before its contents are completely set up.
*
* Callers often assume that this function cannot fail, so don't put any
* elog(ERROR) calls in it.
*
* A possible caller error is to reparent a context under itself, creating
* a loop in the context graph. We assert here that context != new_parent,
* but checking for multi-level loops seems more trouble than it's worth.
*/
void
MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
{
AssertArg(MemoryContextIsValid(context));
AssertArg(context != new_parent);
/* Fast path if it's got correct parent already */
if (new_parent == context->parent)
return;
/* Delink from existing parent, if any */
if (context->parent)
{
MemoryContext parent = context->parent;
if (context == parent->firstchild)
parent->firstchild = context->nextchild;
else
{
MemoryContext child;
for (child = parent->firstchild; child; child = child->nextchild)
{
if (context == child->nextchild)
{
child->nextchild = context->nextchild;
break;
}
}
}
}
/* And relink */
if (new_parent)
{
AssertArg(MemoryContextIsValid(new_parent));
context->parent = new_parent;
context->nextchild = new_parent->firstchild;
new_parent->firstchild = context;
}
else
{
context->parent = NULL;
context->nextchild = NULL;
}
}
示例14: MemoryContextSetParent
/*
* MemoryContextSetParent
* Change a context to belong to a new parent (or no parent).
*
* We provide this as an API function because it is sometimes useful to
* change a context's lifespan after creation. For example, a context
* might be created underneath a transient context, filled with data,
* and then reparented underneath CacheMemoryContext to make it long-lived.
* In this way no special effort is needed to get rid of the context in case
* a failure occurs before its contents are completely set up.
*
* Callers often assume that this function cannot fail, so don't put any
* elog(ERROR) calls in it.
*
* A possible caller error is to reparent a context under itself, creating
* a loop in the context graph. We assert here that context != new_parent,
* but checking for multi-level loops seems more trouble than it's worth.
*/
void
MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
{
AssertArg(MemoryContextIsValid(context));
AssertArg(context != new_parent);
/* Fast path if it's got correct parent already */
if (new_parent == context->parent)
return;
/* Delink from existing parent, if any */
if (context->parent)
{
MemoryContext parent = context->parent;
if (context->prevchild != NULL)
context->prevchild->nextchild = context->nextchild;
else
{
Assert(parent->firstchild == context);
parent->firstchild = context->nextchild;
}
if (context->nextchild != NULL)
context->nextchild->prevchild = context->prevchild;
}
/* And relink */
if (new_parent)
{
AssertArg(MemoryContextIsValid(new_parent));
context->parent = new_parent;
context->prevchild = NULL;
context->nextchild = new_parent->firstchild;
if (new_parent->firstchild != NULL)
new_parent->firstchild->prevchild = context;
new_parent->firstchild = context;
}
else
{
context->parent = NULL;
context->prevchild = NULL;
context->nextchild = NULL;
}
}
示例15: MemoryContextGetCurrentSpace
/*
* MemoryContextGetCurrentSpace
* Return the number of bytes currently occupied by the memory context.
*
* This is the amount of space obtained from the lower-level source of the
* memory (e.g. malloc) and not yet released back to that source. Includes
* overhead and free space held and managed within this context by the
* context-type-specific memory manager.
*/
Size
MemoryContextGetCurrentSpace(MemoryContext context)
{
AssertArg(MemoryContextIsValid(context));
Assert(context->allBytesAlloc >= context->allBytesFreed);
Assert(context->allBytesAlloc - context->allBytesFreed < SIZE_MAX);
return (Size)(context->allBytesAlloc - context->allBytesFreed);
} /* MemoryContextGetCurrentSpace */