~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

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-2011, PostgreSQL Global Development Group
 
11
 * Portions Copyright (c) 1994, Regents of the University of California
 
12
 *
 
13
 * src/include/utils/memutils.h
 
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 VARSIZE_4B() and related macros
 
34
 * in postgres.h.  Many datatypes assume that any allocatable size can
 
35
 * be represented in a varlena header.
 
36
 *
 
37
 * XXX Also, various places in aset.c assume they can compute twice an
 
38
 * allocation's size without overflow, so beware of raising this.
 
39
 */
 
40
#define MaxAllocSize    ((Size) 0x3fffffff)             /* 1 gigabyte - 1 */
 
41
 
 
42
#define AllocSizeIsValid(size)  ((Size) (size) <= MaxAllocSize)
 
43
 
 
44
/*
 
45
 * All chunks allocated by any memory context manager are required to be
 
46
 * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE.
 
47
 * A currently-allocated chunk must contain a backpointer to its owning
 
48
 * context as well as the allocated size of the chunk.  The backpointer is
 
49
 * used by pfree() and repalloc() to find the context to call.  The allocated
 
50
 * size is not absolutely essential, but it's expected to be needed by any
 
51
 * reasonable implementation.
 
52
 */
 
53
typedef struct StandardChunkHeader
 
54
{
 
55
        MemoryContext context;          /* owning context */
 
56
        Size            size;                   /* size of data space allocated in chunk */
 
57
#ifdef MEMORY_CONTEXT_CHECKING
 
58
        /* when debugging memory usage, also store actual requested size */
 
59
        Size            requested_size;
 
60
#endif
 
61
} StandardChunkHeader;
 
62
 
 
63
#define STANDARDCHUNKHEADERSIZE  MAXALIGN(sizeof(StandardChunkHeader))
 
64
 
 
65
 
 
66
/*
 
67
 * Standard top-level memory contexts.
 
68
 *
 
69
 * Only TopMemoryContext and ErrorContext are initialized by
 
70
 * MemoryContextInit() itself.
 
71
 */
 
72
extern PGDLLIMPORT MemoryContext TopMemoryContext;
 
73
extern PGDLLIMPORT MemoryContext ErrorContext;
 
74
extern PGDLLIMPORT MemoryContext PostmasterContext;
 
75
extern PGDLLIMPORT MemoryContext CacheMemoryContext;
 
76
extern PGDLLIMPORT MemoryContext MessageContext;
 
77
extern PGDLLIMPORT MemoryContext TopTransactionContext;
 
78
extern PGDLLIMPORT MemoryContext CurTransactionContext;
 
79
 
 
80
/* This is a transient link to the active portal's memory context: */
 
81
extern PGDLLIMPORT MemoryContext PortalContext;
 
82
 
 
83
 
 
84
/*
 
85
 * Memory-context-type-independent functions in mcxt.c
 
86
 */
 
87
extern void MemoryContextInit(void);
 
88
extern void MemoryContextReset(MemoryContext context);
 
89
extern void MemoryContextDelete(MemoryContext context);
 
90
extern void MemoryContextResetChildren(MemoryContext context);
 
91
extern void MemoryContextDeleteChildren(MemoryContext context);
 
92
extern void MemoryContextResetAndDeleteChildren(MemoryContext context);
 
93
extern Size GetMemoryChunkSpace(void *pointer);
 
94
extern MemoryContext GetMemoryChunkContext(void *pointer);
 
95
extern bool MemoryContextIsEmpty(MemoryContext context);
 
96
extern void MemoryContextStats(MemoryContext context);
 
97
 
 
98
#ifdef MEMORY_CONTEXT_CHECKING
 
99
extern void MemoryContextCheck(MemoryContext context);
 
100
#endif
 
101
extern bool MemoryContextContains(MemoryContext context, void *pointer);
 
102
 
 
103
/*
 
104
 * This routine handles the context-type-independent part of memory
 
105
 * context creation.  It's intended to be called from context-type-
 
106
 * specific creation routines, and noplace else.
 
107
 */
 
108
extern MemoryContext MemoryContextCreate(NodeTag tag, Size size,
 
109
                                        MemoryContextMethods *methods,
 
110
                                        MemoryContext parent,
 
111
                                        const char *name);
 
112
 
 
113
 
 
114
/*
 
115
 * Memory-context-type-specific functions
 
116
 */
 
117
 
 
118
/* aset.c */
 
119
extern MemoryContext AllocSetContextCreate(MemoryContext parent,
 
120
                                          const char *name,
 
121
                                          Size minContextSize,
 
122
                                          Size initBlockSize,
 
123
                                          Size maxBlockSize);
 
124
 
 
125
/*
 
126
 * Recommended default alloc parameters, suitable for "ordinary" contexts
 
127
 * that might hold quite a lot of data.
 
128
 */
 
129
#define ALLOCSET_DEFAULT_MINSIZE   0
 
130
#define ALLOCSET_DEFAULT_INITSIZE  (8 * 1024)
 
131
#define ALLOCSET_DEFAULT_MAXSIZE   (8 * 1024 * 1024)
 
132
 
 
133
/*
 
134
 * Recommended alloc parameters for "small" contexts that are not expected
 
135
 * to contain much data (for example, a context to contain a query plan).
 
136
 */
 
137
#define ALLOCSET_SMALL_MINSIZE   0
 
138
#define ALLOCSET_SMALL_INITSIZE  (1 * 1024)
 
139
#define ALLOCSET_SMALL_MAXSIZE   (8 * 1024)
 
140
 
 
141
#endif   /* MEMUTILS_H */