aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes/memnodes.h
blob: 35adee0d9c3e4968c5f9598df87a613ad7b8a4f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*-------------------------------------------------------------------------
 *
 * memnodes.h--
 *    POSTGRES memory context node definitions.
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 * $Id: memnodes.h,v 1.1.1.1 1996/07/09 06:21:32 scrappy Exp $
 *
 * XXX the typedefs in this file are different from the other ???nodes.h;
 *    they are pointers to structures instead of the structures themselves.
 *    If you're wondering, this is plain laziness. I don't want to touch
 *    the memory context code which should be revamped altogether some day.
 *							- ay 10/94
 *-------------------------------------------------------------------------
 */
#ifndef	MEMNODES_H
#define MEMNODES_H

#include "c.h"

#include "utils/memutils.h"
#include "lib/fstack.h"

#include "nodes/nodes.h"

/*
 * MemoryContext --
 *	A logical context in which memory allocations occur.
 *
 * The types of memory contexts can be thought of as members of the
 * following inheritance hierarchy with properties summarized below.
 *
 *			Node
 *			|
 *		MemoryContext___
 *		/		\
 *	GlobalMemory	PortalMemoryContext
 *			/		\
 *	PortalVariableMemory	PortalHeapMemory
 *
 *			Flushed at	Flushed at	Checkpoints
 *			Transaction	Portal
 *			Commit		Close
 *
 * GlobalMemory			n		n		n
 * PortalVariableMemory		n		y		n
 * PortalHeapMemory		y		y		y
 */

typedef struct MemoryContextMethodsData {
    Pointer	(*alloc)();
    void	(*free_p)(); /* need to use free as a #define,
				so can't use free */
    Pointer	(*realloc)();
    char*	(*getName)();
    void	(*dump)();
} *MemoryContextMethods;

typedef struct MemoryContext {
    NodeTag			type;
    MemoryContextMethods	method;
} *MemoryContext;

/* think about doing this right some time but we'll have explicit fields
   for now -ay 10/94 */
typedef struct GlobalMemory {
    NodeTag			type;
    MemoryContextMethods	method;
    AllocSetData	setData;
    char		*name;
    OrderedElemData	elemData;
} *GlobalMemory;

typedef MemoryContext *PortalMemoryContext;

typedef struct PortalVariableMemory {
    NodeTag			type;
    MemoryContextMethods	method;
    AllocSetData	setData;
} *PortalVariableMemory;

typedef struct PortalHeapMemory {
    NodeTag			type;
    MemoryContextMethods	method;
    Pointer		block;
    FixedStackData	stackData;
} *PortalHeapMemory;

/*
 * MemoryContextIsValid --
 *	True iff memory context is valid.
 */
#define MemoryContextIsValid(context) \
    (IsA(context,MemoryContext) || IsA(context,GlobalMemory) || \
     IsA(context,PortalVariableMemory) || IsA(context,PortalHeapMemory))

#endif	/* MEMNODES_H */