home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / H / utils / mcxt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.7 KB  |  250 lines

  1. /*
  2.  * mcxt.h --
  3.  *    POSTGRES memory context definitions.
  4.  *
  5.  * Identification:
  6.  *    $Header: /private/postgres/src/lib/H/utils/RCS/mcxt.h,v 1.11 1991/11/12 20:24:42 mer Exp $
  7.  */
  8.  
  9. #ifndef    MCxtIncluded
  10. #define MCxtIncluded    1    /* Include this only once */
  11.  
  12. #include "tmp/c.h"
  13.  
  14. #include "nodes/mnodes.h"
  15. #include "nodes/nodes.h"
  16.  
  17. /*
  18.  * CurrentMemoryContext --
  19.  *    Memory context for general global allocations.
  20.  */
  21. extern MemoryContext    CurrentMemoryContext;
  22.  
  23.  
  24. /*
  25.  * EnableMemoryContext --
  26.  *    Enables/disables memory management and global contexts.
  27.  *
  28.  * Note:
  29.  *    This must be called before creating contexts or allocating memory.
  30.  *    This must be called before other contexts are created.
  31.  *
  32.  * Exceptions:
  33.  *    BadArg if on is invalid.
  34.  *    BadState if on is false when disabled.
  35.  */
  36. extern
  37. void
  38. EnableMemoryContext ARGS((
  39.     bool    on
  40. ));
  41.  
  42. /*
  43.  * EnterMemoryManagement --
  44.  *    Initializes the memory management module and the global context.
  45.  *
  46.  * need several classes of these?  and how does this relate to portals?
  47.  *
  48.  * ...
  49.  */
  50.  
  51. /*
  52.  * MemoryContextAlloc --
  53.  *    Returns pointer to aligned allocated memory in the given context.
  54.  *
  55.  * Note:
  56.  *    none
  57.  *
  58.  * Exceptions:
  59.  *    BadState if called before InitMemoryManager.
  60.  *    BadArg if context is invalid or if size is 0.
  61.  *    BadAllocSize if size is larger than MaxAllocSize.
  62.  */
  63. #ifndef PALLOC_DEBUG
  64. extern
  65. Pointer
  66. MemoryContextAlloc ARGS((
  67.     MemoryContext    context,
  68.     Size        size
  69. ));
  70. #else
  71. extern
  72. Pointer
  73. MemoryContextAlloc_Debug ARGS((
  74.     String        file,
  75.     int        line,
  76.         MemoryContext   context,
  77.         Size            size
  78. ));
  79. #endif
  80.  
  81. /*
  82.  * MemoryContextFree --
  83.  *    Frees allocated memory referenced by pointer in the given context.
  84.  *
  85.  * Note:
  86.  *    none
  87.  *
  88.  * Exceptions:
  89.  *    ???
  90.  *    BadArgumentsErr if firstTime is true for subsequent calls.
  91.  */
  92. #ifndef PALLOC_DEBUG
  93. extern
  94. void
  95. MemoryContextFree ARGS((
  96.     MemoryContext    context,
  97.     Pointer        pointer
  98. ));
  99. #else
  100. extern
  101. void
  102. MemoryContextFree_Debug ARGS((
  103.     String        file,
  104.     int        line,
  105.         MemoryContext   context,
  106.         Pointer         pointer
  107. ));
  108. #endif
  109. /*
  110.  * MemoryContextRelloc --
  111.  *    Returns pointer to aligned allocated memory in the given context.
  112.  *
  113.  * Note:
  114.  *    none
  115.  *
  116.  * Exceptions:
  117.  *    ???
  118.  *    BadArgumentsErr if firstTime is true for subsequent calls.
  119.  */
  120. extern
  121. Pointer
  122. MemoryContextRealloc ARGS((
  123.     MemoryContext    context,
  124.     Pointer        pointer,
  125.     Size        size
  126. ));
  127.  
  128. /*
  129.  * MemoryContextGetName --
  130.  *    Returns pointer to aligned allocated memory in the given context.
  131.  *
  132.  * Note:
  133.  *    none
  134.  *
  135.  * Exceptions:
  136.  *    ???
  137.  *    BadArgumentsErr if firstTime is true for subsequent calls.
  138.  */
  139. extern
  140. String
  141. MemoryContextGetName ARGS((
  142.     MemoryContext    context
  143. ));
  144.  
  145. /*
  146.  * PointerGetAllocSize --
  147.  *    Returns size of aligned allocated memory given pointer to it.
  148.  *
  149.  * Note:
  150.  *    none
  151.  *
  152.  * Exceptions:
  153.  *    ???
  154.  *    BadArgumentsErr if firstTime is true for subsequent calls.
  155.  */
  156. extern
  157. Size
  158. PointerGetAllocSize ARGS((
  159.     Pointer    pointer
  160. ));
  161.  
  162. /*
  163.  * MemoryContextSwitchTo --
  164.  *    Returns the current context; installs the given context.
  165.  *
  166.  * Note:
  167.  *    none
  168.  *
  169.  * Exceptions:
  170.  *    BadState if called when disabled.
  171.  *    BadArg if context is invalid.
  172.  */
  173. extern
  174. MemoryContext
  175. MemoryContextSwitchTo ARGS((
  176.     MemoryContext    context
  177. ));
  178.  
  179. /*
  180.  * START HERE
  181.  *    Add routines to move memory between contexts.
  182.  */
  183.  
  184. /*
  185.  * CreateGlobalMemory --
  186.  *    Returns new global memory context.
  187.  *
  188.  * Note:
  189.  *    Assumes name is static.
  190.  *
  191.  * Exceptions:
  192.  *    BadState if called when disabled.
  193.  *    BadState if called outside TopMemoryContext (TopGlobalMemory).
  194.  *    BadArg if name is invalid.
  195.  */
  196. extern
  197. GlobalMemory
  198. CreateGlobalMemory ARGS((
  199.     String    name    /* XXX MemoryContextName */
  200. ));
  201.  
  202. /*
  203.  * GlobalMemoryDestroy --
  204.  *    Destroys given global memory context.
  205.  *
  206.  * Exceptions:
  207.  *    BadState if called when disabled.
  208.  *    BadState if called outside TopMemoryContext (TopGlobalMemory).
  209.  *    BadArg if context is invalid GlobalMemory.
  210.  *    BadArg if context is TopMemoryContext (TopGlobalMemory).
  211.  */
  212. extern
  213. void
  214. GlobalMemoryDestroy ARGS((
  215.     GlobalMemory    context
  216. ));
  217.  
  218. /*
  219.  * TopMemoryContext --
  220.  *    Memory context for general global allocations.
  221.  *
  222.  * Note:
  223.  *    Don't use this memory context for random allocations.  If you
  224.  *    allocate something here, you are expected to clean it up when
  225.  *    appropriate.
  226.  */
  227. extern MemoryContext    TopMemoryContext;
  228.  
  229. /*
  230.  * MaxAllocSize --
  231.  *    Arbitrary limit on size of allocations.
  232.  *
  233.  * Note:
  234.  *    There is no guarantee that allocations smaller than MaxAllocSize
  235.  *    will succeed.  Allocation requests larger than MaxAllocSize will
  236.  *    be summarily denied.
  237.  *
  238.  *    This value should not be referenced except in one place in the code.
  239.  *
  240.  * XXX This should be defined in a file of tunable constants.
  241.  */
  242. #define MaxAllocSize    (0xfffffff)    /* 16G - 1 */
  243.  
  244. /* mcxt.c */
  245. void MemoryContextDump ARGS((MemoryContext context ));
  246. void DumpMemoryContexts ARGS((void ));
  247. void PrintGlobalMemory ARGS((GlobalMemory foo ));
  248.  
  249. #endif /* !defined(MCxtIncluded) */
  250.