~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/include/utils/memutils.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * memutils.h
 
4
 *        This file contains declarations for memory allocation utility
 
5
 *        functions.  These are functions that are not quite widely used
 
6
 *        enough to justify going in utils/palloc.h, but are still part
 
7
 *        of the API of the memory management subsystem.
 
8
 *
 
9
 *
 
10
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
11
 * Portions Copyright (c) 1994, Regents of the University of California
 
12
 *
 
13
 * $PostgreSQL: pgsql/src/include/utils/memutils.h,v 1.59 2004-12-31 22:03:46 pgsql Exp $
 
14
 *
 
15
 *-------------------------------------------------------------------------
 
16
 */
 
17
#ifndef MEMUTILS_H
 
18
#define MEMUTILS_H
 
19
 
 
20
#include "nodes/memnodes.h"
 
21
 
 
22
 
 
23
/*
 
24
 * MaxAllocSize
 
25
 *              Quasi-arbitrary limit on size of allocations.
 
26
 *
 
27
 * Note:
 
28
 *              There is no guarantee that allocations smaller than MaxAllocSize
 
29
 *              will succeed.  Allocation requests larger than MaxAllocSize will
 
30
 *              be summarily denied.
 
31
 *
 
32
 * XXX This is deliberately chosen to correspond to the limiting size
 
33
 * of varlena objects under TOAST.      See VARATT_MASK_SIZE in postgres.h.
 
34
 *
 
35
 * XXX Also, various places in aset.c assume they can compute twice an
 
36
 * allocation's size without overflow, so beware of raising this.
 
37
 */
 
38
#define MaxAllocSize    ((Size) 0x3fffffff)             /* 1 gigabyte - 1 */
 
39
 
 
40
#define AllocSizeIsValid(size)  ((Size) (size) <= MaxAllocSize)
 
41
 
 
42
/*
 
43
 * All chunks allocated by any memory context manager are required to be
 
44
 * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE.
 
45
 * A currently-allocated chunk must contain a backpointer to its owning
 
46
 * context as well as the allocated size of the chunk.  The backpointer is
 
47
 * used by pfree() and repalloc() to find the context to call.  The allocated
 
48
 * size is not absolutely essential, but it's expected to be needed by any
 
49
 * reasonable implementation.
 
50
 */
 
51
typedef struct StandardChunkHeader
 
52
{
 
53
        MemoryContext context;          /* owning context */
 
54
        Size            size;                   /* size of data space allocated in chunk */
 
55
#ifdef MEMORY_CONTEXT_CHECKING
 
56
        /* when debugging memory usage, also store actual requested size */
 
57
        Size            requested_size;
 
58
#endif
 
59
} StandardChunkHeader;
 
60
 
 
61
#define STANDARDCHUNKHEADERSIZE  MAXALIGN(sizeof(StandardChunkHeader))
 
62
 
 
63
 
 
64
/*
 
65
 * Standard top-level memory contexts.
 
66
 *
 
67
 * Only TopMemoryContext and ErrorContext are initialized by
 
68
 * MemoryContextInit() itself.
 
69
 */
 
70
extern DLLIMPORT MemoryContext TopMemoryContext;
 
71
extern DLLIMPORT MemoryContext ErrorContext;
 
72
extern DLLIMPORT MemoryContext PostmasterContext;
 
73
extern DLLIMPORT MemoryContext CacheMemoryContext;
 
74
extern DLLIMPORT MemoryContext MessageContext;
 
75
extern DLLIMPORT MemoryContext TopTransactionContext;
 
76
extern DLLIMPORT MemoryContext CurTransactionContext;
 
77
 
 
78
/* These two are transient links to contexts owned by other objects: */
 
79
extern DLLIMPORT MemoryContext QueryContext;
 
80
extern DLLIMPORT MemoryContext PortalContext;
 
81
 
 
82
 
 
83
/*
 
84
 * Memory-context-type-independent functions in mcxt.c
 
85
 */
 
86
extern void MemoryContextInit(void);
 
87
extern void MemoryContextReset(MemoryContext context);
 
88
extern void MemoryContextDelete(MemoryContext context);
 
89
extern void MemoryContextResetChildren(MemoryContext context);
 
90
extern void MemoryContextDeleteChildren(MemoryContext context);
 
91
extern void MemoryContextResetAndDeleteChildren(MemoryContext context);
 
92
extern Size GetMemoryChunkSpace(void *pointer);
 
93
extern MemoryContext GetMemoryChunkContext(void *pointer);
 
94
extern bool MemoryContextIsEmpty(MemoryContext context);
 
95
extern void MemoryContextStats(MemoryContext context);
 
96
 
 
97
#ifdef MEMORY_CONTEXT_CHECKING
 
98
extern void MemoryContextCheck(MemoryContext context);
 
99
#endif
 
100
extern bool MemoryContextContains(MemoryContext context, void *pointer);
 
101
 
 
102
/*
 
103
 * This routine handles the context-type-independent part of memory
 
104
 * context creation.  It's intended to be called from context-type-
 
105
 * specific creation routines, and noplace else.
 
106
 */
 
107
extern MemoryContext MemoryContextCreate(NodeTag tag, Size size,
 
108
                                        MemoryContextMethods *methods,
 
109
                                        MemoryContext parent,
 
110
                                        const char *name);
 
111
 
 
112
 
 
113
/*
 
114
 * Memory-context-type-specific functions
 
115
 */
 
116
 
 
117
/* aset.c */
 
118
extern MemoryContext AllocSetContextCreate(MemoryContext parent,
 
119
                                          const char *name,
 
120
                                          Size minContextSize,
 
121
                                          Size initBlockSize,
 
122
                                          Size maxBlockSize);
 
123
 
 
124
/*
 
125
 * Recommended default alloc parameters, suitable for "ordinary" contexts
 
126
 * that might hold quite a lot of data.
 
127
 */
 
128
#define ALLOCSET_DEFAULT_MINSIZE   0
 
129
#define ALLOCSET_DEFAULT_INITSIZE  (8 * 1024)
 
130
#define ALLOCSET_DEFAULT_MAXSIZE   (8 * 1024 * 1024)
 
131
 
 
132
/*
 
133
 * Recommended alloc parameters for "small" contexts that are not expected
 
134
 * to contain much data (for example, a context to contain a query plan).
 
135
 */
 
136
#define ALLOCSET_SMALL_MINSIZE   0
 
137
#define ALLOCSET_SMALL_INITSIZE  (1 * 1024)
 
138
#define ALLOCSET_SMALL_MAXSIZE   (8 * 1024)
 
139
 
 
140
#endif   /* MEMUTILS_H */