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

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    memutils.h
  4.  *
  5.  *   DESCRIPTION
  6.  *    this file contains general memory alignment, allocation
  7.  *    and manipulation stuff that used to be spread out
  8.  *    between the following files:
  9.  *
  10.  *    align.h                alignment macros
  11.  *    aset.h                memory allocation set stuff
  12.  *    oset.h                  (used by aset.h)
  13.  *    bit.h                bit array type / extern
  14.  *    clib.h                mem routines
  15.  *    limit.h                max bits/byte, etc.
  16.  *
  17.  *   NOTES
  18.  *    some of the information in this file will be moved to
  19.  *    other files, (like MaxHeapTupleSize and MaxAttributeSize).
  20.  *
  21.  *   IDENTIFICATION
  22.  *    $Header: /private/postgres/src/lib/H/utils/RCS/memutils.h,v 1.5 1991/11/12 20:24:42 mer Exp $
  23.  * ----------------------------------------------------------------
  24.  */
  25. #ifndef MemutilsHIncluded
  26. #define MemutilsHIncluded 1
  27.  
  28. #include "tmp/c.h"
  29.  
  30. /* ----------------
  31.  *    align.h
  32.  * ----------------
  33.  */
  34. #ifndef    _ALIGN_H_
  35. #define    _ALIGN_H_    "$Header: /private/postgres/src/lib/H/utils/RCS/memutils.h,v 1.5 1991/11/12 20:24:42 mer Exp $"
  36.  
  37. /*
  38.  *    align.h        - alignment macros
  39.  */
  40.  
  41. /*
  42.  *    SHORTALIGN(LEN)    - length (or address) aligned for shorts
  43.  */
  44. #define    SHORTALIGN(LEN)\
  45.     (((long)(LEN) + 1) & ~01)
  46.  
  47. /*
  48.  *    LONGALIGN(LEN)    - length (or address) aligned for longs
  49.  */
  50. #if defined(sun) && ! defined(sparc)
  51. #define    LONGALIGN(LEN)    SHORTALIGN(LEN)
  52. #else 
  53. #define    LONGALIGN(LEN)\
  54.     (((long)(LEN) + 3) & ~03)
  55. #endif
  56.  
  57. #endif _ALIGN_H_
  58.  
  59. /* ----------------
  60.  *    bit.h
  61.  * ----------------
  62.  */
  63. /*
  64.  * bit.h --
  65.  *    Standard bit array definitions.
  66.  *
  67.  * Identification:
  68.  *    $Header: /private/postgres/src/lib/H/utils/RCS/memutils.h,v 1.5 1991/11/12 20:24:42 mer Exp $
  69.  */
  70.  
  71. #ifndef    BitIncluded    /* Include this file only once. */
  72. #define BitIncluded    1
  73.  
  74. /* #include "tmp/c.h" (now at the top of memutils.h) */
  75.  
  76. typedef bits8    *BitArray;
  77. typedef uint32    BitIndex;
  78.  
  79. #define BitsPerByte    8
  80.  
  81. /*
  82.  * NumberOfBitsPerByte --
  83.  *    Returns the number of bits per byte.
  84.  */
  85. int
  86. NumberOfBitsPerByte ARGS((
  87.     void
  88. ));
  89.  
  90. /*
  91.  * BitArraySetBit --
  92.  *    Sets (to 1) the value of a bit in a bit array.
  93.  */
  94. void
  95. BitArraySetBit ARGS((
  96.     BitArray    bitArray,
  97.     BitIndex    bitIndex
  98. ));
  99.  
  100. /*
  101.  * BitArrayClearBit --
  102.  *    Clears (to 0) the value of a bit in a bit array.
  103.  */
  104. void
  105. BitArrayClearBit ARGS((
  106.     BitArray    bitArray,
  107.     BitIndex    bitIndex
  108. ));
  109.  
  110. /*
  111.  * BitArrayBitIsSet --
  112.  *    True iff the bit is set (1) in a bit array.
  113.  */
  114. bool
  115. BitArrayBitIsSet ARGS((
  116.     BitArray    bitArray,
  117.     BitIndex    bitIndex
  118. ));
  119.  
  120. /*
  121.  * BitArrayCopy --
  122.  *    Copys the contents of one bit array into another.
  123.  */
  124. void
  125. BitArrayCopy ARGS((
  126.     BitArray    fromBitArray,
  127.     BitArray    toBitArray,
  128.     BitIndex    fromBitIndex,
  129.     BitIndex    toBitIndex,
  130.     BitIndex    numberOfBits
  131. ));
  132.  
  133. /*
  134.  * BitArrayZero --
  135.  *    Zeros the contents of a bit array.
  136.  */
  137. void
  138. BitArrayZero ARGS((
  139.     BitArray    bitArray,
  140.     BitIndex    bitIndex,
  141.     BitIndex    numberOfBits
  142. ));
  143.  
  144. #endif    /* !defined(BitIncluded) */
  145.  
  146. /* ----------------
  147.  *    oset.h
  148.  * ----------------
  149.  */
  150. /*
  151.  * oset.h --
  152.  *    Fixed format ordered set definitions.
  153.  *
  154.  * Note:
  155.  *    Fixed format ordered sets are <EXPLAIN>.
  156.  *    XXX This is a preliminary version.  Work is needed to explain
  157.  *    XXX semantics of the external definitions.  Otherwise, the
  158.  *    XXX functional interface should not change.
  159.  *
  160.  * Identification:
  161.  *    $Header: /private/postgres/src/lib/H/utils/RCS/memutils.h,v 1.5 1991/11/12 20:24:42 mer Exp $
  162.  */
  163.  
  164. #ifndef    OSetIncluded        /* Include this only once */
  165. #define OSetIncluded    1
  166.  
  167. /* #include "tmp/c.h"     (now at the top of memutils.h) */
  168.  
  169. typedef struct OrderedElemData OrderedElemData;
  170. typedef OrderedElemData* OrderedElem;
  171.  
  172. typedef struct OrderedSetData OrderedSetData;
  173. typedef OrderedSetData* OrderedSet;
  174.  
  175. struct OrderedElemData {
  176.     OrderedElem    next;    /* Next elem or &this->set->dummy    */
  177.     OrderedElem    prev;    /* Previous elem or &this->set->head    */
  178.     OrderedSet    set;    /* Parent set                */
  179. };
  180.  
  181. struct OrderedSetData {
  182.     OrderedElem    head;    /* First elem or &this->dummy        */
  183.     OrderedElem    dummy;    /* (hack) Terminator == NULL        */
  184.     OrderedElem    tail;    /* Last elem or &this->head        */
  185.     Offset        offset;    /* Offset from struct base to elem    */
  186.     /* this could be signed short int! */
  187. };
  188.  
  189. /*
  190.  * OrderedSetInit --
  191.  */
  192. extern
  193. void
  194. OrderedSetInit ARGS((
  195.     OrderedSet    set,
  196.     Offset        offset
  197. ));
  198.  
  199. /*
  200.  * OrderedElemInit --
  201.  */
  202. extern
  203. void
  204. OrderedElemInit ARGS((
  205.     OrderedElem    elem,
  206.     OrderedSet    set
  207. ));
  208.  
  209. /*
  210.  * OrderedSetContains --
  211.  *    True iff ordered set contains given element.
  212.  */
  213. extern
  214. bool
  215. OrderedSetContains ARGS((
  216.     OrderedSet    set,
  217.     OrderedElem    elem
  218. ));
  219.  
  220. /*
  221.  * OrderedSetGetHead --
  222.  */
  223. extern
  224. Pointer
  225. OrderedSetGetHead ARGS((
  226.     OrderedSet    set
  227. ));
  228.  
  229. /*
  230.  * OrderedSetGetTail --
  231.  */
  232. extern
  233. Pointer
  234. OrderedSetGetTail ARGS((
  235.     OrderedSet    set
  236. ));
  237.  
  238. /*
  239.  * OrderedElemGetPredecessor --
  240.  */
  241. extern
  242. Pointer
  243. OrderedElemGetPredecessor ARGS((
  244.     OrderedElem    elem
  245. ));
  246.  
  247. /*
  248.  * OrderedElemGetSuccessor --
  249.  */
  250. extern
  251. Pointer
  252. OrderedElemGetSuccessor ARGS((
  253.     OrderedElem    elem
  254. ));
  255.  
  256. /*
  257.  * OrderedElemPop --
  258.  */
  259. extern
  260. void
  261. OrderedElemPop ARGS((
  262.     OrderedElem    elem
  263. ));
  264.  
  265. /*
  266.  * OrderedElemPushInto --
  267.  */
  268. extern
  269. void
  270. OrderedElemPushInto ARGS((
  271.     OrderedElem    elem,
  272.     OrderedSet    set
  273. ));
  274.  
  275. /*
  276.  * OrderedElemPush --
  277.  */
  278. extern
  279. void
  280. OrderedElemPush ARGS((
  281.     OrderedElem    elem
  282. ));
  283.  
  284. /*
  285.  * OrderedElemPushHead --
  286.  */
  287. extern
  288. void
  289. OrderedElemPushHead ARGS((
  290.     OrderedElem    elem
  291. ));
  292.  
  293. /*
  294.  * OrderedElemPushTail --
  295.  */
  296. extern
  297. void
  298. OrderedElemPushTail ARGS((
  299.     OrderedElem    elem
  300. ));
  301.  
  302. /*
  303.  * OrderedElemPushAfter --
  304.  */
  305. extern
  306. void
  307. OrderedElemPushAfter ARGS((
  308.     OrderedElem    elem,
  309.     OrderedElem    oldElem
  310. ));
  311.  
  312. /*
  313.  * OrderedElemPushBefore --
  314.  */
  315. extern
  316. void
  317. OrderedElemPushBefore ARGS((
  318.     OrderedElem    elem,
  319.     OrderedElem    oldElem
  320. ));
  321.  
  322. /*
  323.  * OrderedSetPop --
  324.  */
  325. extern
  326. Pointer
  327. OrderedSetPop ARGS((
  328.     OrderedSet    set
  329. ));
  330.  
  331. /*
  332.  * OrderedSetPopHead --
  333.  */
  334. extern
  335. Pointer
  336. OrderedSetPopHead ARGS((
  337.     OrderedSet    set
  338. ));
  339.  
  340. /*
  341.  * OrderedSetPopTail --
  342.  */
  343. extern
  344. Pointer
  345. OrderedSetPopTail ARGS((
  346.     OrderedSet    set
  347. ));
  348.  
  349. #endif    /* !defined(OSetIncluded) */
  350.  
  351. /* ----------------
  352.  *    aset.h
  353.  * ----------------
  354.  */
  355. /*
  356.  * aset.h --
  357.  *    Allocation set definitions.
  358.  *
  359.  * Identification:
  360.  *    $Header: /private/postgres/src/lib/H/utils/RCS/memutils.h,v 1.5 1991/11/12 20:24:42 mer Exp $
  361.  *
  362.  * Description:
  363.  *    An allocation set is a set containing allocated elements.  When
  364.  *    an allocation is requested for a set, memory is allocated and a
  365.  *    pointer is returned.  Subsequently, this memory may be freed or
  366.  *    reallocated.  In addition, an allocation set may be reset which
  367.  *    will cause all allocated memory to be freed.
  368.  *
  369.  *    Allocations may occur in four different modes.  The mode of
  370.  *    allocation does not affect the behavior of allocations except in
  371.  *    terms of performance.  The allocation mode is set at the time of
  372.  *    set initialization.  Once the mode is chosen, it cannot be changed
  373.  *    unless the set is reinitialized.
  374.  *
  375.  *    "Dynamic" mode forces all allocations to occur in a heap.  This
  376.  *    is a good mode to use when small memory segments are allocated
  377.  *    and freed very frequently.  This is a good choice when allocation
  378.  *    characteristics are unknown.  This is the default mode.
  379.  *
  380.  *    "Static" mode attemts to allocate space as efficiently as possible
  381.  *    without regard to freeing memory.  This mode should be chosen only
  382.  *    when it is known that many allocations will occur but that very
  383.  *    little of the allocated memory will be explicitly freed.
  384.  *
  385.  *    "Tunable" mode is a hybrid of dynamic and static modes.  The
  386.  *    tunable mode will use static mode allocation except when the
  387.  *    allocation request exceeds a size limit supplied at the time of set
  388.  *    initialization.  "Big" objects are allocated using dynamic mode.
  389.  *
  390.  *    "Bounded" mode attempts to allocate space efficiently given a limit
  391.  *    on space consumed by the allocation set.  This restriction can be
  392.  *    considered a "soft" restriction, because memory segments will
  393.  *    continue to be returned after the limit is exceeded.  The limit is
  394.  *    specified at the time of set initialization like for tunable mode.
  395.  *
  396.  * Note:
  397.  *    Allocation sets are not automatically reset on a system reset.
  398.  *    Higher level code is responsible for cleaning up.
  399.  *
  400.  *    There may other modes in the future.
  401.  */
  402.  
  403. #ifndef    ASetIncluded        /* Include this file only once */
  404. #define ASetIncluded    1
  405.  
  406. /* #include "tmp/c.h" (now at the top of memutils.h) */
  407. /* #include "tmp/oset.h" (now just above this stuff in memutils.h) */
  408.  
  409. /*
  410.  * AllocPointer --
  411.  *    Aligned pointer which may be a member of an allocation set.
  412.  */
  413. typedef Pointer AllocPointer;
  414.  
  415. /*
  416.  * AllocMode --
  417.  *    Mode of allocation for an allocation set.
  418.  *
  419.  * Note:
  420.  *    See above for a description of the various nodes.
  421.  */
  422. typedef enum AllocMode {
  423.     DynamicAllocMode,    /* always dynamically allocate */
  424.     StaticAllocMode,    /* always "statically" allocate */
  425.     TunableAllocMode,    /* allocations are "tuned" */
  426.     BoundedAllocMode    /* allocations bounded to fixed usage */
  427.  
  428. #define DefaultAllocMode    DynamicAllocMode
  429. } AllocMode;
  430.  
  431. /*
  432.  * AllocSet --
  433.  *    Allocation set.
  434.  */
  435.  
  436. typedef struct AllocSetData {
  437.     OrderedSetData    setData;
  438.     /* Note: this will change in the future to support other modes */
  439. } AllocSetData;
  440.  
  441. typedef AllocSetData *AllocSet;
  442.  
  443. /*
  444.  * AllocPointerIsValid --
  445.  *    True iff pointer is valid allocation pointer.
  446.  */
  447. #define AllocPointerIsValid(pointer) PointerIsValid(pointer)
  448.  
  449. /*
  450.  * AllocSetIsValid --
  451.  *    True iff set is valid allocation set.
  452.  */
  453. #define AllocSetIsValid(set) PointerIsValid(set)    
  454.  
  455. /*
  456.  * AllocSetInit --
  457.  *    Initializes given allocation set.
  458.  *
  459.  * Note:
  460.  *    The semantics of the mode are explained above.  Limit is ignored
  461.  *    for dynamic and static modes.
  462.  *
  463.  * Exceptions:
  464.  *    BadArg if set is invalid pointer.
  465.  *    BadArg if mode is invalid.
  466.  */
  467. extern
  468. void
  469. AllocSetInit ARGS((
  470.     AllocSet    set,
  471.     AllocMode    mode,
  472.     Size        limit
  473. ));
  474.  
  475. /*
  476.  * AllocSetReset --
  477.  *    Frees memory which is allocated in the given set.
  478.  *
  479.  * Exceptions:
  480.  *    BadArg if set is invalid.
  481.  */
  482. #ifndef PALLOC_DEBUG
  483. extern void AllocSetReset ARGS((AllocSet set));
  484. #else    
  485. void AllocSetReset_debug ARGS((String file , int line , AllocSet set ));
  486. #endif PALLOC_DEBUG
  487.  
  488. /*
  489.  * AllocSetContains --
  490.  *    True iff allocation set contains given allocation element.
  491.  *
  492.  * Exceptions:
  493.  *    BadArg if set is invalid.
  494.  *    BadArg if pointer is invalid.
  495.  */
  496. extern
  497. bool
  498. AllocSetContains ARGS((
  499.     AllocSet    set,
  500.     AllocPointer    pointer
  501. ));
  502.  
  503. /*
  504.  * AllocSetAlloc --
  505.  *    Returns pointer to allocated memory of given size; memory is added
  506.  *    to the set.
  507.  *
  508.  * Exceptions:
  509.  *    BadArg if set is invalid.
  510.  *    MemoryExhausted if allocation fails.
  511.  */
  512. extern
  513. AllocPointer
  514. AllocSetAlloc ARGS((
  515.     AllocSet    set,
  516.     Size        size
  517. ));
  518.  
  519. /*
  520.  * AllocSetFree --
  521.  *    Frees allocated memory; memory is removed from the set.
  522.  *
  523.  * Exceptions:
  524.  *    BadArg if set is invalid.
  525.  *    BadArg if pointer is invalid.
  526.  *    BadArg if pointer is not member of set.
  527.  */
  528. extern
  529. void
  530. AllocSetFree ARGS((
  531.     AllocSet    set,
  532.     AllocPointer    pointer
  533. ));
  534.  
  535. /*
  536.  * AllocSetRealloc --
  537.  *    Returns new pointer to allocated memory of given size; this memory
  538.  *    is added to the set.  Memory associated with given pointer is copied
  539.  *    into the new memory, and the old memory is freed.
  540.  *
  541.  * Exceptions:
  542.  *    BadArg if set is invalid.
  543.  *    BadArg if pointer is invalid.
  544.  *    BadArg if pointer is not member of set.
  545.  *    MemoryExhausted if allocation fails.
  546.  */
  547. extern
  548. AllocPointer
  549. AllocSetRealloc ARGS((
  550.     AllocSet    set,
  551.     AllocPointer    pointer,
  552.     Size        size
  553. ));
  554.  
  555.  
  556. /*
  557.  * AllocSetIterate --
  558.  *    Returns size of set.  Iterates through set elements calling function
  559.  *    (if valid) on each.
  560.  *
  561.  * Note:
  562.  *    This was written as an aid to debugging.  It is intended for
  563.  *    debugging use only.
  564.  *
  565.  * Exceptions:
  566.  *    BadArg if set is invalid.
  567.  */
  568. extern
  569. Count
  570. AllocSetStep ARGS((
  571.     AllocSet    set,
  572.     void        (*function) ARGS((AllocPointer pointer))
  573. ));
  574.  
  575. extern
  576. Count
  577. AllocSetStep ARGS((
  578.     AllocSet    set,
  579.     void        (*function) ARGS((AllocPointer pointer))
  580. ));
  581.  
  582. Count AllocSetCount ARGS((AllocSet set));
  583. void AllocPointerDump ARGS((AllocPointer pointer));
  584. void AllocSetDump ARGS((AllocSet set));
  585.  
  586. #endif    /* !defined(ASetIncluded) */
  587.  
  588. /* ----------------
  589.  *    clib.h
  590.  * ----------------
  591.  */
  592. /*
  593.  * clib.h --
  594.  *    Standard C library definitions.
  595.  *
  596.  * Note:
  597.  *    This file is OPERATING SYSTEM dependent!!!
  598.  *
  599.  * Identification:
  600.  *    $Header: /private/postgres/src/lib/H/utils/RCS/memutils.h,v 1.5 1991/11/12 20:24:42 mer Exp $
  601.  */
  602.  
  603. #ifndef    CLibIncluded    /* Include this file only once. */
  604. #define CLibIncluded    1
  605.  
  606. /* #include "tmp/c.h" (now at the top of memutils.h) */
  607. #include <memory.h>
  608.  
  609. /* 
  610.  *    LibCCopyLength is only used within this file. -cim 6/12/90
  611.  * 
  612.  */
  613. typedef int    LibCCopyLength;
  614.  
  615. typedef     CLibCopyLength;
  616.  
  617. /*
  618.  * MemoryCopy --
  619.  *    Copies fixed length block of memory to another.
  620.  */
  621. #define MemoryCopy(toBuffer, fromBuffer, length)\
  622.     memcpy(toBuffer, fromBuffer, length)
  623.  
  624. #endif    /* !defined(CLibIncluded) */
  625.  
  626. /* ----------------
  627.  *    limit.h
  628.  * ----------------
  629.  */
  630. /*
  631.  * limit.h --
  632.  *    POSTGRES limit definitions.
  633.  *
  634.  * Identification:
  635.  *    $Header: /private/postgres/src/lib/H/utils/RCS/memutils.h,v 1.5 1991/11/12 20:24:42 mer Exp $
  636.  */
  637.  
  638. #ifndef    LimitIncluded    /* Include this file only once. */
  639. #define LimitIncluded    1
  640.  
  641. /* #include "tmp/c.h" (now at the top of memutils.h) */
  642.  
  643. #define MaxBitsPerByte    8
  644.  
  645. typedef uint32    AttributeSize;    /* XXX should be defined elsewhere */
  646.  
  647. #define MaxHeapTupleSize    0x7fffffff
  648. #define MaxAttributeSize    0x7fffffff
  649.  
  650. #define MaxIndexAttributeNumber    7
  651.  
  652. /*
  653.  * AttributeSizeIsValid --
  654.  *    True iff the attribute size is valid.
  655.  */
  656. extern
  657. bool
  658. AttributeSizeIsValid ARGS((
  659.     AttributeSize    size
  660. ));
  661.  
  662. /*
  663.  * TupleSizeIsValid --
  664.  *    True iff the tuple size is valid.
  665.  */
  666. extern
  667. bool
  668. TupleSizeIsValid();/* BAD PROTOTYPE DELETED -- glass */
  669. /*    ARGS((
  670.     TupleSize    size
  671. ));*/
  672.  
  673. #endif    /* !defined(LimitIncluded) */
  674.  
  675. #endif MemutilsHIncluded
  676.