1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* mcxt.c--
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES memory context code.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1999-02-06 17:50:34 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.11 1999/02/06 16:50:26 wieck Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#include <stdio.h> /* XXX for printf debugging */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "utils/memutils.h"
|
|
|
|
#include "utils/module.h"
|
|
|
|
#include "utils/excid.h"
|
|
|
|
|
|
|
|
#include "nodes/memnodes.h"
|
|
|
|
#include "nodes/nodes.h"
|
|
|
|
|
|
|
|
#include "utils/mcxt.h"
|
|
|
|
#include "utils/elog.h"
|
|
|
|
|
|
|
|
#include "utils/palloc.h"
|
|
|
|
|
|
|
|
#undef MemoryContextAlloc
|
|
|
|
#undef MemoryContextFree
|
|
|
|
#undef malloc
|
|
|
|
#undef free
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global State
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static int MemoryContextEnableCount = 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#define MemoryContextEnabled (MemoryContextEnableCount > 0)
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
static OrderedSetData ActiveGlobalMemorySetData; /* uninitialized */
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#define ActiveGlobalMemorySet (&ActiveGlobalMemorySetData)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* description of allocated memory representation goes here
|
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PSIZE(PTR) (*((int32 *)(PTR) - 1))
|
1996-07-09 08:22:35 +02:00
|
|
|
#define PSIZEALL(PTR) (*((int32 *)(PTR) - 1) + sizeof (int32))
|
|
|
|
#define PSIZESKIP(PTR) ((char *)((int32 *)(PTR) + 1))
|
|
|
|
#define PSIZEFIND(PTR) ((char *)((int32 *)(PTR) - 1))
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PSIZESPACE(LEN) ((LEN) + sizeof (int32))
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AllocSizeIsValid --
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff 0 < size and size <= MaxAllocSize.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define AllocSizeIsValid(size) (0 < (size) && (size) <= MaxAllocSize)
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* GLOBAL MEMORY *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CurrentMemoryContext --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Memory context for general global allocations.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
MemoryContext CurrentMemoryContext = NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* PRIVATE DEFINITIONS *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
static Pointer GlobalMemoryAlloc(GlobalMemory this, Size size);
|
|
|
|
static void GlobalMemoryFree(GlobalMemory this, Pointer pointer);
|
1998-09-01 06:40:42 +02:00
|
|
|
static Pointer GlobalMemoryRealloc(GlobalMemory this, Pointer pointer,
|
1997-09-07 07:04:48 +02:00
|
|
|
Size size);
|
1997-09-08 04:41:22 +02:00
|
|
|
static char *GlobalMemoryGetName(GlobalMemory this);
|
|
|
|
static void GlobalMemoryDump(GlobalMemory this);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-11-08 07:02:30 +01:00
|
|
|
#ifdef NOT_USED
|
1997-09-08 04:41:22 +02:00
|
|
|
static void DumpGlobalMemories(void);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-11-08 07:02:30 +01:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Global Memory Methods
|
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
static struct MemoryContextMethodsData GlobalContextMethodsData = {
|
|
|
|
GlobalMemoryAlloc, /* Pointer (*)(this, uint32) palloc */
|
|
|
|
GlobalMemoryFree, /* void (*)(this, Pointer) pfree */
|
|
|
|
GlobalMemoryRealloc, /* Pointer (*)(this, Pointer) repalloc */
|
|
|
|
GlobalMemoryGetName, /* char* (*)(this) getName */
|
|
|
|
GlobalMemoryDump /* void (*)(this) dump */
|
1996-07-09 08:22:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* TopGlobalMemory is handled specially because of bootstrapping.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
/* extern bool EqualGlobalMemory(); */
|
|
|
|
|
1999-02-06 17:50:34 +01:00
|
|
|
static struct GlobalMemoryData TopGlobalMemoryData = {
|
1997-09-07 07:04:48 +02:00
|
|
|
T_GlobalMemory, /* NodeTag tag */
|
|
|
|
&GlobalContextMethodsData, /* ContextMethods method */
|
1999-02-06 17:50:34 +01:00
|
|
|
{ NULL, { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }},
|
|
|
|
/* free AllocSet */
|
1997-09-07 07:04:48 +02:00
|
|
|
"TopGlobal", /* char* name */
|
|
|
|
{0} /* uninitialized OrderedElemData elemD */
|
1996-07-09 08:22:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TopMemoryContext --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Memory context for general global allocations.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Don't use this memory context for random allocations. If you
|
|
|
|
* allocate something here, you are expected to clean it up when
|
|
|
|
* appropriate.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
MemoryContext TopMemoryContext = (MemoryContext) &TopGlobalMemoryData;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module State
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EnableMemoryContext --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Enables/disables memory management and global contexts.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* This must be called before creating contexts or allocating memory.
|
|
|
|
* This must be called before other contexts are created.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* BadArg if on is invalid.
|
|
|
|
* BadState if on is false when disabled.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
EnableMemoryContext(bool on)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
static bool processing = false;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
AssertState(!processing);
|
|
|
|
AssertArg(BoolIsValid(on));
|
|
|
|
|
|
|
|
if (BypassEnable(&MemoryContextEnableCount, on))
|
|
|
|
return;
|
|
|
|
|
|
|
|
processing = true;
|
|
|
|
|
|
|
|
if (on)
|
|
|
|
{ /* initialize */
|
|
|
|
/* initialize TopGlobalMemoryData.setData */
|
|
|
|
AllocSetInit(&TopGlobalMemoryData.setData, DynamicAllocMode,
|
|
|
|
(Size) 0);
|
|
|
|
|
|
|
|
/* make TopGlobalMemoryData member of ActiveGlobalMemorySet */
|
|
|
|
OrderedSetInit(ActiveGlobalMemorySet,
|
1999-02-06 17:50:34 +01:00
|
|
|
offsetof(struct GlobalMemoryData, elemData));
|
1997-09-07 07:04:48 +02:00
|
|
|
OrderedElemPushInto(&TopGlobalMemoryData.elemData,
|
|
|
|
ActiveGlobalMemorySet);
|
|
|
|
|
|
|
|
/* initialize CurrentMemoryContext */
|
|
|
|
CurrentMemoryContext = TopMemoryContext;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* cleanup */
|
1997-09-08 04:41:22 +02:00
|
|
|
GlobalMemory context;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* walk the list of allocations */
|
|
|
|
while (PointerIsValid(context = (GlobalMemory)
|
|
|
|
OrderedSetGetHead(ActiveGlobalMemorySet)))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (context == &TopGlobalMemoryData)
|
|
|
|
{
|
|
|
|
/* don't free it and clean it last */
|
|
|
|
OrderedElemPop(&TopGlobalMemoryData.elemData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GlobalMemoryDestroy(context);
|
|
|
|
/* what is needed for the top? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Freeing memory here should be safe as this is called only after
|
|
|
|
* all modules which allocate in TopMemoryContext have been
|
|
|
|
* disabled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* step through remaining allocations and log */
|
|
|
|
/* AllocSetStep(...); */
|
|
|
|
|
|
|
|
/* deallocate whatever is left */
|
|
|
|
AllocSetReset(&TopGlobalMemoryData.setData);
|
|
|
|
}
|
|
|
|
|
|
|
|
processing = false;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MemoryContextAlloc --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns pointer to aligned allocated memory in the given context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* none
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* BadState if called before InitMemoryManager.
|
|
|
|
* BadArg if context is invalid or if size is 0.
|
|
|
|
* BadAllocSize if size is larger than MaxAllocSize.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
Pointer
|
|
|
|
MemoryContextAlloc(MemoryContext context, Size size)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
AssertArg(MemoryContextIsValid(context));
|
|
|
|
|
|
|
|
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
|
|
|
|
("size=%d [0x%x]", size, size));
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return context->method->alloc(context, size);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MemoryContextFree --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Frees allocated memory referenced by pointer in the given context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* none
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ???
|
|
|
|
* BadArgumentsErr if firstTime is true for subsequent calls.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
MemoryContextFree(MemoryContext context, Pointer pointer)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
AssertArg(MemoryContextIsValid(context));
|
|
|
|
AssertArg(PointerIsValid(pointer));
|
|
|
|
|
|
|
|
context->method->free_p(context, pointer);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MemoryContextRelloc --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns pointer to aligned allocated memory in the given context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* none
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ???
|
|
|
|
* BadArgumentsErr if firstTime is true for subsequent calls.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
Pointer
|
|
|
|
MemoryContextRealloc(MemoryContext context,
|
1997-09-07 07:04:48 +02:00
|
|
|
Pointer pointer,
|
|
|
|
Size size)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
AssertArg(MemoryContextIsValid(context));
|
|
|
|
AssertArg(PointerIsValid(pointer));
|
|
|
|
|
|
|
|
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
|
|
|
|
("size=%d [0x%x]", size, size));
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return context->method->realloc(context, pointer, size);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MemoryContextGetName --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns pointer to aligned allocated memory in the given context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* none
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ???
|
|
|
|
* BadArgumentsErr if firstTime is true for subsequent calls.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-08-19 23:40:56 +02:00
|
|
|
#ifdef NOT_USED
|
1998-02-26 05:46:47 +01:00
|
|
|
char *
|
1996-07-09 08:22:35 +02:00
|
|
|
MemoryContextGetName(MemoryContext context)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
AssertArg(MemoryContextIsValid(context));
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return context->method->getName(context);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-08-19 23:40:56 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PointerGetAllocSize --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns size of aligned allocated memory given pointer to it.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* none
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ???
|
|
|
|
* BadArgumentsErr if firstTime is true for subsequent calls.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-08-19 23:40:56 +02:00
|
|
|
#ifdef NOT_USED
|
1996-07-09 08:22:35 +02:00
|
|
|
Size
|
|
|
|
PointerGetAllocSize(Pointer pointer)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
AssertArg(PointerIsValid(pointer));
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return PSIZE(pointer);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-08-19 23:40:56 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MemoryContextSwitchTo --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns the current context; installs the given context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* none
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* BadState if called when disabled.
|
|
|
|
* BadArg if context is invalid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
MemoryContext
|
|
|
|
MemoryContextSwitchTo(MemoryContext context)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
MemoryContext old;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
AssertArg(MemoryContextIsValid(context));
|
|
|
|
|
|
|
|
old = CurrentMemoryContext;
|
|
|
|
CurrentMemoryContext = context;
|
1998-09-01 05:29:17 +02:00
|
|
|
return old;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* External Functions
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* CreateGlobalMemory --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns new global memory context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes name is static.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* BadState if called when disabled.
|
|
|
|
* BadState if called outside TopMemoryContext (TopGlobalMemory).
|
|
|
|
* BadArg if name is invalid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
GlobalMemory
|
1997-09-08 23:56:23 +02:00
|
|
|
CreateGlobalMemory(char *name) /* XXX MemoryContextName */
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
GlobalMemory context;
|
|
|
|
MemoryContext savecxt;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
|
|
|
|
savecxt = MemoryContextSwitchTo(TopMemoryContext);
|
|
|
|
|
1999-02-06 17:50:34 +01:00
|
|
|
context = (GlobalMemory) newNode(sizeof(struct GlobalMemoryData), T_GlobalMemory);
|
1997-09-07 07:04:48 +02:00
|
|
|
context->method = &GlobalContextMethodsData;
|
|
|
|
context->name = name; /* assumes name is static */
|
|
|
|
AllocSetInit(&context->setData, DynamicAllocMode, (Size) 0);
|
|
|
|
|
|
|
|
/* link the context */
|
|
|
|
OrderedElemPushInto(&context->elemData, ActiveGlobalMemorySet);
|
|
|
|
|
|
|
|
MemoryContextSwitchTo(savecxt);
|
1998-09-01 05:29:17 +02:00
|
|
|
return context;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalMemoryDestroy --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Destroys given global memory context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* BadState if called when disabled.
|
|
|
|
* BadState if called outside TopMemoryContext (TopGlobalMemory).
|
|
|
|
* BadArg if context is invalid GlobalMemory.
|
|
|
|
* BadArg if context is TopMemoryContext (TopGlobalMemory).
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
GlobalMemoryDestroy(GlobalMemory context)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
AssertState(MemoryContextEnabled);
|
|
|
|
AssertArg(IsA(context, GlobalMemory));
|
|
|
|
AssertArg(context != &TopGlobalMemoryData);
|
|
|
|
|
|
|
|
AllocSetReset(&context->setData);
|
|
|
|
|
|
|
|
/* unlink and delete the context */
|
|
|
|
OrderedElemPop(&context->elemData);
|
|
|
|
MemoryContextFree(TopMemoryContext, (Pointer) context);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* PRIVATE *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalMemoryAlloc --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns pointer to aligned space in the global context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExhaustedMemory if allocation fails.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static Pointer
|
1996-07-09 08:22:35 +02:00
|
|
|
GlobalMemoryAlloc(GlobalMemory this, Size size)
|
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return AllocSetAlloc(&this->setData, size);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalMemoryFree --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Frees allocated memory in the global context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* BadContextErr if current context is not the global context.
|
|
|
|
* BadArgumentsErr if pointer is invalid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
GlobalMemoryFree(GlobalMemory this,
|
1997-09-07 07:04:48 +02:00
|
|
|
Pointer pointer)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
AllocSetFree(&this->setData, pointer);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalMemoryRealloc --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns pointer to aligned space in the global context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Memory associated with the pointer is freed before return.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* BadContextErr if current context is not the global context.
|
|
|
|
* BadArgumentsErr if pointer is invalid.
|
|
|
|
* NoMoreMemoryErr if allocation fails.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static Pointer
|
1996-07-09 08:22:35 +02:00
|
|
|
GlobalMemoryRealloc(GlobalMemory this,
|
1997-09-07 07:04:48 +02:00
|
|
|
Pointer pointer,
|
|
|
|
Size size)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return AllocSetRealloc(&this->setData, pointer, size);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalMemoryGetName --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns name string for context.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ???
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static char *
|
1996-07-09 08:22:35 +02:00
|
|
|
GlobalMemoryGetName(GlobalMemory this)
|
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return this->name;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalMemoryDump --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Dumps global memory context for debugging.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ???
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
GlobalMemoryDump(GlobalMemory this)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
GlobalMemory context;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
printf("--\n%s:\n", GlobalMemoryGetName(this));
|
|
|
|
|
|
|
|
context = (GlobalMemory) OrderedElemGetPredecessor(&this->elemData);
|
|
|
|
if (PointerIsValid(context))
|
|
|
|
printf("\tpredecessor=%s\n", GlobalMemoryGetName(context));
|
|
|
|
|
|
|
|
context = (GlobalMemory) OrderedElemGetSuccessor(&this->elemData);
|
|
|
|
if (PointerIsValid(context))
|
|
|
|
printf("\tsucessor=%s\n", GlobalMemoryGetName(context));
|
|
|
|
|
|
|
|
AllocSetDump(&this->setData); /* XXX is this right interface */
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DumpGlobalMemories --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Dumps all global memory contexts for debugging.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Exceptions:
|
1997-09-07 07:04:48 +02:00
|
|
|
* ???
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1996-11-08 07:02:30 +01:00
|
|
|
#ifdef NOT_USED
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
|
|
|
DumpGlobalMemories()
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
GlobalMemory context;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
context = (GlobalMemory) OrderedSetGetHead(&ActiveGlobalMemorySetData);
|
|
|
|
|
|
|
|
while (PointerIsValid(context))
|
|
|
|
{
|
|
|
|
GlobalMemoryDump(context);
|
|
|
|
|
|
|
|
context = (GlobalMemory) OrderedElemGetSuccessor(
|
|
|
|
&context->elemData);
|
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-11-08 07:02:30 +01:00
|
|
|
#endif
|