~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/include/nodes/memnodes.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * memnodes.h
 
4
 *        POSTGRES memory context node definitions.
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * $PostgreSQL$
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef MEMNODES_H
 
15
#define MEMNODES_H
 
16
 
 
17
#include "nodes/nodes.h"
 
18
 
 
19
/*
 
20
 * MemoryContext
 
21
 *              A logical context in which memory allocations occur.
 
22
 *
 
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
 
27
 * in C++ terms.
 
28
 *
 
29
 * Node types that are actual implementations of memory contexts must
 
30
 * begin with the same fields as MemoryContext.
 
31
 *
 
32
 * Note: for largely historical reasons, typedef MemoryContext is a pointer
 
33
 * to the context struct rather than the struct type itself.
 
34
 */
 
35
 
 
36
typedef struct MemoryContextMethods
 
37
{
 
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);
 
50
#endif
 
51
} MemoryContextMethods;
 
52
 
 
53
 
 
54
typedef struct MemoryContextData
 
55
{
 
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) */
 
62
} MemoryContextData;
 
63
 
 
64
/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
 
65
 
 
66
 
 
67
/*
 
68
 * MemoryContextIsValid
 
69
 *              True iff memory context is valid.
 
70
 *
 
71
 * Add new context types to the set accepted by this macro.
 
72
 */
 
73
#define MemoryContextIsValid(context) \
 
74
        ((context) != NULL && \
 
75
         (IsA((context), AllocSetContext)))
 
76
 
 
77
#endif   /* MEMNODES_H */