Header And Logo

PostgreSQL
| The world's most advanced open source database.

memnodes.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * memnodes.h
00004  *    POSTGRES memory context node definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/nodes/memnodes.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef MEMNODES_H
00015 #define MEMNODES_H
00016 
00017 #include "nodes/nodes.h"
00018 
00019 /*
00020  * MemoryContext
00021  *      A logical context in which memory allocations occur.
00022  *
00023  * MemoryContext itself is an abstract type that can have multiple
00024  * implementations, though for now we have only AllocSetContext.
00025  * The function pointers in MemoryContextMethods define one specific
00026  * implementation of MemoryContext --- they are a virtual function table
00027  * in C++ terms.
00028  *
00029  * Node types that are actual implementations of memory contexts must
00030  * begin with the same fields as MemoryContext.
00031  *
00032  * Note: for largely historical reasons, typedef MemoryContext is a pointer
00033  * to the context struct rather than the struct type itself.
00034  */
00035 
00036 typedef struct MemoryContextMethods
00037 {
00038     void       *(*alloc) (MemoryContext context, Size size);
00039     /* call this free_p in case someone #define's free() */
00040     void        (*free_p) (MemoryContext context, void *pointer);
00041     void       *(*realloc) (MemoryContext context, void *pointer, Size size);
00042     void        (*init) (MemoryContext context);
00043     void        (*reset) (MemoryContext context);
00044     void        (*delete_context) (MemoryContext context);
00045     Size        (*get_chunk_space) (MemoryContext context, void *pointer);
00046     bool        (*is_empty) (MemoryContext context);
00047     void        (*stats) (MemoryContext context, int level);
00048 #ifdef MEMORY_CONTEXT_CHECKING
00049     void        (*check) (MemoryContext context);
00050 #endif
00051 } MemoryContextMethods;
00052 
00053 
00054 typedef struct MemoryContextData
00055 {
00056     NodeTag     type;           /* identifies exact kind of context */
00057     MemoryContextMethods *methods;      /* virtual function table */
00058     MemoryContext parent;       /* NULL if no parent (toplevel context) */
00059     MemoryContext firstchild;   /* head of linked list of children */
00060     MemoryContext nextchild;    /* next child of same parent */
00061     char       *name;           /* context name (just for debugging) */
00062     bool        isReset;        /* T = no space alloced since last reset */
00063 } MemoryContextData;
00064 
00065 /* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
00066 
00067 
00068 /*
00069  * MemoryContextIsValid
00070  *      True iff memory context is valid.
00071  *
00072  * Add new context types to the set accepted by this macro.
00073  */
00074 #define MemoryContextIsValid(context) \
00075     ((context) != NULL && \
00076      (IsA((context), AllocSetContext)))
00077 
00078 #endif   /* MEMNODES_H */