Eneboo - Documentación para desarrolladores
|
00001 /*------------------------------------------------------------------------- 00002 * 00003 * memutils.h 00004 * This file contains declarations for memory allocation utility 00005 * functions. These are functions that are not quite widely used 00006 * enough to justify going in utils/palloc.h, but are still part 00007 * of the API of the memory management subsystem. 00008 * 00009 * 00010 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group 00011 * Portions Copyright (c) 1994, Regents of the University of California 00012 * 00013 * $PostgreSQL: pgsql/src/include/utils/memutils.h,v 1.59 2004/12/31 22:03:46 pgsql Exp $ 00014 * 00015 *------------------------------------------------------------------------- 00016 */ 00017 #ifndef MEMUTILS_H 00018 #define MEMUTILS_H 00019 00020 #include "nodes/memnodes.h" 00021 00022 00023 /* 00024 * MaxAllocSize 00025 * Quasi-arbitrary limit on size of allocations. 00026 * 00027 * Note: 00028 * There is no guarantee that allocations smaller than MaxAllocSize 00029 * will succeed. Allocation requests larger than MaxAllocSize will 00030 * be summarily denied. 00031 * 00032 * XXX This is deliberately chosen to correspond to the limiting size 00033 * of varlena objects under TOAST. See VARATT_MASK_SIZE in postgres.h. 00034 * 00035 * XXX Also, various places in aset.c assume they can compute twice an 00036 * allocation's size without overflow, so beware of raising this. 00037 */ 00038 #define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */ 00039 00040 #define AllocSizeIsValid(size) ((Size) (size) <= MaxAllocSize) 00041 00042 /* 00043 * All chunks allocated by any memory context manager are required to be 00044 * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE. 00045 * A currently-allocated chunk must contain a backpointer to its owning 00046 * context as well as the allocated size of the chunk. The backpointer is 00047 * used by pfree() and repalloc() to find the context to call. The allocated 00048 * size is not absolutely essential, but it's expected to be needed by any 00049 * reasonable implementation. 00050 */ 00051 typedef struct StandardChunkHeader 00052 { 00053 MemoryContext context; /* owning context */ 00054 Size size; /* size of data space allocated in chunk */ 00055 #ifdef MEMORY_CONTEXT_CHECKING 00056 /* when debugging memory usage, also store actual requested size */ 00057 Size requested_size; 00058 #endif 00059 } StandardChunkHeader; 00060 00061 #define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader)) 00062 00063 00064 /* 00065 * Standard top-level memory contexts. 00066 * 00067 * Only TopMemoryContext and ErrorContext are initialized by 00068 * MemoryContextInit() itself. 00069 */ 00070 extern DLLIMPORT MemoryContext TopMemoryContext; 00071 extern DLLIMPORT MemoryContext ErrorContext; 00072 extern DLLIMPORT MemoryContext PostmasterContext; 00073 extern DLLIMPORT MemoryContext CacheMemoryContext; 00074 extern DLLIMPORT MemoryContext MessageContext; 00075 extern DLLIMPORT MemoryContext TopTransactionContext; 00076 extern DLLIMPORT MemoryContext CurTransactionContext; 00077 00078 /* These two are transient links to contexts owned by other objects: */ 00079 extern DLLIMPORT MemoryContext QueryContext; 00080 extern DLLIMPORT MemoryContext PortalContext; 00081 00082 00083 /* 00084 * Memory-context-type-independent functions in mcxt.c 00085 */ 00086 extern void MemoryContextInit(void); 00087 extern void MemoryContextReset(MemoryContext context); 00088 extern void MemoryContextDelete(MemoryContext context); 00089 extern void MemoryContextResetChildren(MemoryContext context); 00090 extern void MemoryContextDeleteChildren(MemoryContext context); 00091 extern void MemoryContextResetAndDeleteChildren(MemoryContext context); 00092 extern Size GetMemoryChunkSpace(void *pointer); 00093 extern MemoryContext GetMemoryChunkContext(void *pointer); 00094 extern bool MemoryContextIsEmpty(MemoryContext context); 00095 extern void MemoryContextStats(MemoryContext context); 00096 00097 #ifdef MEMORY_CONTEXT_CHECKING 00098 extern void MemoryContextCheck(MemoryContext context); 00099 #endif 00100 extern bool MemoryContextContains(MemoryContext context, void *pointer); 00101 00102 /* 00103 * This routine handles the context-type-independent part of memory 00104 * context creation. It's intended to be called from context-type- 00105 * specific creation routines, and noplace else. 00106 */ 00107 extern MemoryContext MemoryContextCreate(NodeTag tag, Size size, 00108 MemoryContextMethods *methods, 00109 MemoryContext parent, 00110 const char *name); 00111 00112 00113 /* 00114 * Memory-context-type-specific functions 00115 */ 00116 00117 /* aset.c */ 00118 extern MemoryContext AllocSetContextCreate(MemoryContext parent, 00119 const char *name, 00120 Size minContextSize, 00121 Size initBlockSize, 00122 Size maxBlockSize); 00123 00124 /* 00125 * Recommended default alloc parameters, suitable for "ordinary" contexts 00126 * that might hold quite a lot of data. 00127 */ 00128 #define ALLOCSET_DEFAULT_MINSIZE 0 00129 #define ALLOCSET_DEFAULT_INITSIZE (8 * 1024) 00130 #define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024) 00131 00132 /* 00133 * Recommended alloc parameters for "small" contexts that are not expected 00134 * to contain much data (for example, a context to contain a query plan). 00135 */ 00136 #define ALLOCSET_SMALL_MINSIZE 0 00137 #define ALLOCSET_SMALL_INITSIZE (1 * 1024) 00138 #define ALLOCSET_SMALL_MAXSIZE (8 * 1024) 00139 00140 #endif /* MEMUTILS_H */