1
/*-------------------------------------------------------------------------
4
* POSTGRES memory context node definitions.
7
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
12
*-------------------------------------------------------------------------
17
#include "nodes/nodes.h"
21
* A logical context in which memory allocations occur.
23
* MemoryContext itself is an abstract type that can have multiple
24
* implementations, though for now we have only AllocSetContext.
25
* The function pointers in MemoryContextMethods define one specific
26
* implementation of MemoryContext --- they are a virtual function table
29
* Node types that are actual implementations of memory contexts must
30
* begin with the same fields as MemoryContext.
32
* Note: for largely historical reasons, typedef MemoryContext is a pointer
33
* to the context struct rather than the struct type itself.
36
typedef struct MemoryContextMethods
38
void *(*alloc) (MemoryContext context, Size size);
39
/* call this free_p in case someone #define's free() */
40
void (*free_p) (MemoryContext context, void *pointer);
41
void *(*realloc) (MemoryContext context, void *pointer, Size size);
42
void (*init) (MemoryContext context);
43
void (*reset) (MemoryContext context);
44
void (*delete) (MemoryContext context);
45
Size (*get_chunk_space) (MemoryContext context, void *pointer);
46
bool (*is_empty) (MemoryContext context);
47
void (*stats) (MemoryContext context, int level);
48
#ifdef MEMORY_CONTEXT_CHECKING
49
void (*check) (MemoryContext context);
51
} MemoryContextMethods;
54
typedef struct MemoryContextData
56
NodeTag type; /* identifies exact kind of context */
57
MemoryContextMethods *methods; /* virtual function table */
58
MemoryContext parent; /* NULL if no parent (toplevel context) */
59
MemoryContext firstchild; /* head of linked list of children */
60
MemoryContext nextchild; /* next child of same parent */
61
char *name; /* context name (just for debugging) */
64
/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
68
* MemoryContextIsValid
69
* True iff memory context is valid.
71
* Add new context types to the set accepted by this macro.
73
#define MemoryContextIsValid(context) \
74
((context) != NULL && \
75
(IsA((context), AllocSetContext)))
77
#endif /* MEMNODES_H */