1996-08-27 21:59:28 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
1999-02-13 18:22:53 -05:00
|
|
|
* memnodes.h
|
1997-09-07 01:04:48 -04:00
|
|
|
* POSTGRES memory context node definitions.
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
|
|
|
|
*
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
2000-06-27 23:33:33 -04:00
|
|
|
* $Id: memnodes.h,v 1.17 2000/06/28 03:33:15 tgl Exp $
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
1997-09-07 01:04:48 -04:00
|
|
|
#ifndef MEMNODES_H
|
1996-08-27 21:59:28 -04:00
|
|
|
#define MEMNODES_H
|
|
|
|
|
|
1999-07-15 19:04:24 -04:00
|
|
|
#include "nodes/nodes.h"
|
1996-08-27 21:59:28 -04:00
|
|
|
|
|
|
|
|
/*
|
1999-05-25 12:15:34 -04:00
|
|
|
* MemoryContext
|
1997-09-07 01:04:48 -04:00
|
|
|
* A logical context in which memory allocations occur.
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
2000-06-27 23:33:33 -04:00
|
|
|
* MemoryContext itself is an abstract type that can have multiple
|
|
|
|
|
* implementations, though for now we have only AllocSetContext.
|
|
|
|
|
* The function pointers in MemoryContextMethods define one specific
|
|
|
|
|
* implementation of MemoryContext --- they are a virtual function table
|
|
|
|
|
* in C++ terms.
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
2000-06-27 23:33:33 -04:00
|
|
|
* Node types that are actual implementations of memory contexts must
|
|
|
|
|
* begin with the same fields as MemoryContext.
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
2000-06-27 23:33:33 -04:00
|
|
|
* Note: for largely historical reasons, typedef MemoryContext is a pointer
|
|
|
|
|
* to the context struct rather than the struct type itself.
|
1996-08-27 21:59:28 -04:00
|
|
|
*/
|
|
|
|
|
|
2000-06-27 23:33:33 -04:00
|
|
|
typedef struct MemoryContextMethods
|
1997-09-07 01:04:48 -04:00
|
|
|
{
|
2000-06-27 23:33:33 -04:00
|
|
|
void *(*alloc) (MemoryContext context, Size size);
|
|
|
|
|
/* call this free_p in case someone #define's free() */
|
|
|
|
|
void (*free_p) (MemoryContext context, void *pointer);
|
|
|
|
|
void *(*realloc) (MemoryContext context, void *pointer, Size size);
|
|
|
|
|
void (*init) (MemoryContext context);
|
|
|
|
|
void (*reset) (MemoryContext context);
|
|
|
|
|
void (*delete) (MemoryContext context);
|
|
|
|
|
void (*stats) (MemoryContext context);
|
|
|
|
|
} MemoryContextMethods;
|
|
|
|
|
|
1996-08-27 21:59:28 -04:00
|
|
|
|
1999-02-06 11:50:34 -05:00
|
|
|
typedef struct MemoryContextData
|
1997-09-07 01:04:48 -04:00
|
|
|
{
|
2000-06-27 23:33:33 -04:00
|
|
|
NodeTag type; /* identifies exact kind of context */
|
|
|
|
|
MemoryContextMethods *methods; /* virtual function table */
|
|
|
|
|
MemoryContext parent; /* NULL if no parent (toplevel context) */
|
|
|
|
|
MemoryContext firstchild; /* head of linked list of children */
|
|
|
|
|
MemoryContext nextchild; /* next child of same parent */
|
|
|
|
|
char *name; /* context name (just for debugging) */
|
1999-05-25 18:43:53 -04:00
|
|
|
} MemoryContextData;
|
1999-03-07 18:03:32 -05:00
|
|
|
|
2000-06-27 23:33:33 -04:00
|
|
|
/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
|
1996-08-27 21:59:28 -04:00
|
|
|
|
1999-03-07 18:03:32 -05:00
|
|
|
|
2000-06-27 23:33:33 -04:00
|
|
|
/*
|
|
|
|
|
* AllocSetContext is our standard implementation of MemoryContext.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct AllocBlockData *AllocBlock; /* internal to aset.c */
|
|
|
|
|
typedef struct AllocChunkData *AllocChunk;
|
1996-08-27 21:59:28 -04:00
|
|
|
|
2000-06-27 23:33:33 -04:00
|
|
|
typedef struct AllocSetContext
|
1997-09-07 01:04:48 -04:00
|
|
|
{
|
2000-06-27 23:33:33 -04:00
|
|
|
MemoryContextData header; /* Standard memory-context fields */
|
|
|
|
|
/* Info about storage allocated in this context: */
|
|
|
|
|
AllocBlock blocks; /* head of list of blocks in this set */
|
|
|
|
|
#define ALLOCSET_NUM_FREELISTS 8
|
|
|
|
|
AllocChunk freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */
|
|
|
|
|
/* Allocation parameters for this context: */
|
|
|
|
|
Size initBlockSize; /* initial block size */
|
|
|
|
|
Size maxBlockSize; /* maximum block size */
|
|
|
|
|
AllocBlock keeper; /* if not NULL, keep this block
|
|
|
|
|
* over resets */
|
|
|
|
|
} AllocSetContext;
|
1996-08-27 21:59:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-05-25 12:15:34 -04:00
|
|
|
* MemoryContextIsValid
|
1997-09-07 01:04:48 -04:00
|
|
|
* True iff memory context is valid.
|
2000-06-27 23:33:33 -04:00
|
|
|
*
|
|
|
|
|
* Add new context types to the set accepted by this macro.
|
1996-08-27 21:59:28 -04:00
|
|
|
*/
|
|
|
|
|
#define MemoryContextIsValid(context) \
|
2000-06-27 23:33:33 -04:00
|
|
|
((context) != NULL && \
|
|
|
|
|
(IsA((context), AllocSetContext)))
|
|
|
|
|
|
1996-08-27 21:59:28 -04:00
|
|
|
|
1998-09-01 00:40:42 -04:00
|
|
|
#endif /* MEMNODES_H */
|