summaryrefslogtreecommitdiff
path: root/src/include/nodes/memnodes.h
blob: 08ba9673181d6ed9d8d60a3d032d4c546aeda869 (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
102
103
104
105
106
/*-------------------------------------------------------------------------
 *
 * memnodes.h
 *	  POSTGRES memory context node definitions.
 *
 *
 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $Id: memnodes.h,v 1.16 2000/01/26 05:58:16 momjian 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 "lib/fstack.h"
#include "nodes/nodes.h"
#include "utils/memutils.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 MemoryContextData
{
	NodeTag		type;
	MemoryContextMethods method;
} MemoryContextData;

/* utils/mcxt.h contains typedef struct MemoryContextData *MemoryContext */

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

/* utils/mcxt.h contains typedef struct GlobalMemoryData *GlobalMemory */

typedef struct MemoryContextData *PortalMemoryContext;

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

typedef struct PortalHeapMemoryData
{
	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 */