1 /*-------------------------------------------------------------------------
4 * POSTGRES memory context node definitions.
7 * Portions Copyright (c) 2003-2008, PgPool Global Development Group
8 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/include/nodes/memnodes.h,v 1.30 2004/12/31 22:03:34 pgsql Exp $
13 *-------------------------------------------------------------------------
22 * A logical context in which memory allocations occur.
24 * MemoryContext itself is an abstract type that can have multiple
25 * implementations, though for now we have only AllocSetContext.
26 * The function pointers in MemoryContextMethods define one specific
27 * implementation of MemoryContext --- they are a virtual function table
30 * Node types that are actual implementations of memory contexts must
31 * begin with the same fields as MemoryContext.
33 * Note: for largely historical reasons, typedef MemoryContext is a pointer
34 * to the context struct rather than the struct type itself.
37 typedef struct MemoryContextMethods
39 void *(*alloc) (MemoryContext context, Size size);
40 /* call this free_p in case someone #define's free() */
41 void (*free_p) (MemoryContext context, void *pointer);
42 void *(*realloc) (MemoryContext context, void *pointer, Size size);
43 void (*init) (MemoryContext context);
44 void (*reset) (MemoryContext context);
45 void (*delete) (MemoryContext context);
46 Size (*get_chunk_space) (MemoryContext context, void *pointer);
47 bool (*is_empty) (MemoryContext context);
48 void (*stats) (MemoryContext context);
49 #ifdef MEMORY_CONTEXT_CHECKING
50 void (*check) (MemoryContext context);
52 } MemoryContextMethods;
55 typedef struct MemoryContextData
57 NodeTag type; /* identifies exact kind of context */
58 MemoryContextMethods *methods; /* virtual function table */
59 MemoryContext parent; /* NULL if no parent (toplevel context) */
60 MemoryContext firstchild; /* head of linked list of children */
61 MemoryContext nextchild; /* next child of same parent */
62 char *name; /* context name (just for debugging) */
65 /* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
69 * MemoryContextIsValid
70 * True iff memory context is valid.
72 * Add new context types to the set accepted by this macro.
74 #define MemoryContextIsValid(context) \
75 ((context) != NULL && \
76 (IsA((context), AllocSetContext)))
78 #endif /* MEMNODES_H */