home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / winheap.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  5KB  |  164 lines

  1. /***
  2. *winheap.h - Private include file for winheap directory.
  3. *
  4. *       Copyright (c) 1988-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Contains information needed by the C library heap code.
  8. *
  9. *       [Internal]
  10. *
  11. ****/
  12.  
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif  /* _MSC_VER > 1000 */
  16.  
  17. #ifndef _INC_WINHEAP
  18. #define _INC_WINHEAP
  19.  
  20. #ifndef _CRTBLD
  21. /*
  22.  * This is an internal C runtime header file. It is used when building
  23.  * the C runtimes only. It is not to be used as a public header file.
  24.  */
  25. #error ERROR: Use of C runtime library internal header file.
  26. #endif  /* _CRTBLD */
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif  /* __cplusplus */
  31.  
  32. #include <windows.h>
  33.  
  34. #define BYTES_PER_PARA      16
  35. #define DWORDS_PER_PARA     4
  36.  
  37. #define PARAS_PER_PAGE      256     //  tunable value
  38. #define PAGES_PER_GROUP     8       //  tunable value
  39. #define GROUPS_PER_REGION   32      //  tunable value (max 32)
  40.  
  41. #define BYTES_PER_PAGE      (BYTES_PER_PARA * PARAS_PER_PAGE)
  42. #define BYTES_PER_GROUP     (BYTES_PER_PAGE * PAGES_PER_GROUP)
  43. #define BYTES_PER_REGION    (BYTES_PER_GROUP * GROUPS_PER_REGION)
  44.  
  45. #define ENTRY_OFFSET        0x0000000cL     //  offset of entry in para
  46. #define OVERHEAD_PER_PAGE   0x00000010L     //  sixteen bytes of overhead
  47. #define MAX_FREE_ENTRY_SIZE (BYTES_PER_PAGE - OVERHEAD_PER_PAGE)
  48. #define BITV_COMMIT_INIT    (((1 << GROUPS_PER_REGION) - 1) << \
  49.                                             (32 - GROUPS_PER_REGION))
  50. #define MAX_ALLOC_DATA_SIZE     0x3f8
  51. #define MAX_ALLOC_ENTRY_SIZE    (MAX_ALLOC_DATA_SIZE + 0x8)
  52.  
  53. typedef unsigned int    BITVEC;
  54.  
  55. typedef struct tagListHead
  56. {
  57.     struct tagEntry *   pEntryNext;
  58.     struct tagEntry *   pEntryPrev;
  59. }
  60. LISTHEAD, *PLISTHEAD;
  61.  
  62. typedef struct tagEntry
  63. {
  64.     int                 sizeFront;
  65.     struct tagEntry *   pEntryNext;
  66.     struct tagEntry *   pEntryPrev;
  67. }
  68. ENTRY, *PENTRY;
  69.  
  70. typedef struct tagEntryEnd
  71. {
  72.     int                 sizeBack;
  73. }
  74. ENTRYEND, *PENTRYEND;
  75.  
  76. typedef struct tagGroup
  77. {
  78.     int                 cntEntries;
  79.     struct tagListHead  listHead[64];
  80. }
  81. GROUP, *PGROUP;
  82.  
  83. typedef struct tagRegion
  84. {
  85.     int                 indGroupUse;
  86.     char                cntRegionSize[64];
  87.     BITVEC              bitvGroupHi[GROUPS_PER_REGION];
  88.     BITVEC              bitvGroupLo[GROUPS_PER_REGION];
  89.     struct tagGroup     grpHeadList[GROUPS_PER_REGION];
  90. }
  91. REGION, *PREGION;
  92.  
  93. typedef struct tagHeader
  94. {
  95.     BITVEC              bitvEntryHi;
  96.     BITVEC              bitvEntryLo;
  97.     BITVEC              bitvCommit;
  98.     void *              pHeapData;
  99.     struct tagRegion *  pRegion;
  100. }
  101. HEADER, *PHEADER;
  102.  
  103. extern  HANDLE _crtheap;
  104.  
  105. /*
  106.  * Global variable declarations for the small-block heap.
  107.  */
  108. extern size_t       __sbh_threshold;
  109.  
  110. void * __cdecl _nh_malloc(size_t, int);
  111. void * __cdecl _heap_alloc(size_t);
  112.  
  113. extern PHEADER      __sbh_pHeaderList;        //  pointer to list start
  114. extern PHEADER      __sbh_pHeaderScan;        //  pointer to list rover
  115. extern int          __sbh_sizeHeaderList;     //  allocated size of list
  116. extern int          __sbh_cntHeaderList;      //  count of entries defined
  117.  
  118. extern PHEADER      __sbh_pHeaderDefer;
  119. extern int          __sbh_indGroupDefer;
  120.  
  121. extern size_t  __cdecl _get_sb_threshold(void);
  122. extern int     __cdecl _set_sb_threshold(size_t);
  123.  
  124. extern int     __cdecl _heap_init(int);
  125. extern void    __cdecl _heap_term(void);
  126.  
  127. extern void *  __cdecl _malloc_base(size_t);
  128. extern void *  __cdecl _nh_malloc_base(size_t, int);
  129. extern void *  __cdecl _heap_alloc_base(size_t);
  130.  
  131. extern void    __cdecl _free_base(void *);
  132. extern void *  __cdecl _realloc_base(void *, size_t);
  133.  
  134. extern void *  __cdecl _expand_base(void *, size_t);
  135. extern void *  __cdecl _calloc_base(size_t, size_t);
  136.  
  137. extern size_t  __cdecl _msize_base(void *);
  138.  
  139. extern int     __cdecl __sbh_heap_init(void);
  140.  
  141. extern void *  __cdecl __sbh_alloc_block(int);
  142. extern PHEADER __cdecl __sbh_alloc_new_region(void);
  143. extern int     __cdecl __sbh_alloc_new_group(PHEADER);
  144.  
  145. extern PHEADER __cdecl __sbh_find_block(void *);
  146.  
  147. #ifdef _DEBUG
  148. extern int     __cdecl __sbh_verify_block(PHEADER, void *);
  149. #endif  /* _DEBUG */
  150.  
  151. extern void    __cdecl __sbh_free_block(PHEADER, void *);
  152. extern int     __cdecl __sbh_resize_block(PHEADER, void *, int);
  153.  
  154. extern void    __cdecl __sbh_heapmin(void);
  155.  
  156. extern int     __cdecl __sbh_heap_check(void);
  157.  
  158.  
  159. #ifdef __cplusplus
  160. }
  161. #endif  /* __cplusplus */
  162.  
  163. #endif  /* _INC_WINHEAP */
  164.