home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / MALLOC.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  7KB  |  195 lines

  1. /*
  2.  *  malloc.h    Memory allocation functions
  3.  *
  4.  *  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  5.  */
  6. #ifndef _MALLOC_H_INCLUDED
  7. #define _MALLOC_H_INCLUDED
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11.  
  12. #ifndef _COMDEF_H_INCLUDED
  13.  #include <_comdef.h>
  14. #endif
  15.  
  16. #if defined(_M_IX86)
  17.   #pragma pack(__push,1);
  18. #else
  19.   #pragma pack(__push,8);
  20. #endif
  21.  
  22. #ifndef _SIZE_T_DEFINED
  23. #define _SIZE_T_DEFINED
  24. #define _SIZE_T_DEFINED_
  25. typedef unsigned size_t;
  26. #endif
  27.  
  28. #ifndef NULL
  29.  #if defined(__SMALL__) || defined(__MEDIUM__) || defined(__386__) || defined(__AXP__) || defined(__PPC__)
  30.   #define NULL   0
  31.  #else
  32.   #define NULL   0L
  33.  #endif
  34. #endif
  35.  
  36. #ifndef alloca
  37.  _WCRTLINK extern void  *alloca(size_t __size);
  38.  _WCRTLINK extern void  *_alloca(size_t __size);
  39.  _WCRTLINK extern unsigned stackavail( void );
  40.  #if defined(__AXP__) || defined(__PPC__)
  41.   extern void *__builtin_alloca(size_t __size);
  42.   #pragma intrinsic(__builtin_alloca);
  43.   
  44.   #define __alloca( s )  (__builtin_alloca(s))
  45.   
  46.   #define alloca( s )   ((s<stackavail())?__alloca(s):NULL)
  47.   #define _alloca( s )  ((s<stackavail())?__alloca(s):NULL)
  48.  #else
  49.   extern void  *__doalloca(size_t __size);
  50.   #pragma aux stackavail __modify __nomemory;
  51.  
  52.   #define __ALLOCA_ALIGN( s )   (((s)+(sizeof(int)-1))&~(sizeof(int)-1))
  53.   #define __alloca( s )         __doalloca(__ALLOCA_ALIGN(s))
  54.  
  55.   #if defined(__386__)
  56.    extern void __GRO(size_t __size);
  57.    #pragma aux __GRO "*" __parm __routine [];
  58.    #define alloca( s )  ((__ALLOCA_ALIGN(s)<stackavail())?(__GRO(__ALLOCA_ALIGN(s)),__alloca(s)):NULL)
  59.    #define _alloca( s ) ((__ALLOCA_ALIGN(s)<stackavail())?(__GRO(__ALLOCA_ALIGN(s)),__alloca(s)):NULL)
  60.   #else
  61.    #define alloca( s )  ((__ALLOCA_ALIGN(s)<stackavail())?__alloca(s):NULL)
  62.    #define _alloca( s ) ((__ALLOCA_ALIGN(s)<stackavail())?__alloca(s):NULL)
  63.   #endif
  64.  
  65.   #if defined(__386__)
  66.    #pragma aux     __doalloca =              \
  67.         "sub esp,eax"                    \
  68.         __parm __nomemory [__eax] __value [__esp] __modify __exact __nomemory [__esp];
  69.   #elif defined(__SMALL__) || defined(__MEDIUM__) /* small data models */
  70.    #pragma aux __doalloca = \
  71.         "sub sp,ax"     \
  72.         __parm __nomemory [__ax] __value [__sp] __modify __exact __nomemory [__sp];
  73.   #else                          /* large data models */
  74.    #pragma aux __doalloca = \
  75.         "sub sp,ax"     \
  76.         "mov ax,sp"     \
  77.         "mov dx,ss"     \
  78.         __parm __nomemory [__ax] __value [__dx __ax] __modify __exact __nomemory [__dx __ax __sp];
  79.   #endif
  80.  #endif
  81. #endif
  82.  
  83. #define _HEAPOK     0
  84. #define _HEAPEMPTY    1    /* heap isn't initialized */
  85. #define _HEAPBADBEGIN    2    /* heap header is corrupted */
  86. #define _HEAPBADNODE    3    /* heap entry is corrupted */
  87. #define _HEAPEND    4    /* end of heap entries (_heapwalk) */
  88. #define _HEAPBADPTR    5    /* invalid heap entry pointer (_heapwalk) */
  89.  
  90. #define _USEDENTRY    0
  91. #define _FREEENTRY    1
  92.  
  93. typedef struct _heapinfo {
  94.     void _WCFAR    *_pentry;    /* heap pointer */
  95.     size_t    _size;        /* heap entry size */
  96.     int        _useflag;    /* heap entry 'in-use' flag */
  97. } _HEAPINFO;
  98.  
  99. _WCRTLINK extern int _heapenable( int __enabled );
  100. _WCRTLINK extern int _heapchk( void );
  101. _WCRTLINK extern int _nheapchk( void );
  102. _WCRTLINK extern int _fheapchk( void );
  103. _WCRTLINK extern int _heapset( unsigned int __fill );
  104. _WCRTLINK extern int _nheapset( unsigned int __fill );
  105. _WCRTLINK extern int _fheapset( unsigned int __fill );
  106. _WCRTLINK extern int _heapwalk( struct _heapinfo *__entry );
  107. _WCRTLINK extern int _nheapwalk( struct _heapinfo *__entry );
  108. _WCRTLINK extern int _fheapwalk( struct _heapinfo *__entry );
  109.  
  110. _WCRTLINK extern void _heapgrow( void );
  111. _WCRTLINK extern void _nheapgrow( void );
  112. _WCRTLINK extern void _fheapgrow( void );
  113. _WCRTLINK extern int _heapmin( void );
  114. _WCRTLINK extern int _nheapmin( void );
  115. _WCRTLINK extern int _fheapmin( void );
  116. _WCRTLINK extern int _heapshrink( void );
  117. _WCRTLINK extern int _nheapshrink( void );
  118. _WCRTLINK extern int _fheapshrink( void );
  119.  
  120. _WCRTLINK extern int __nmemneed( size_t );
  121. _WCRTLINK extern int __fmemneed( size_t );
  122. #if !defined(_fcalloc) || !defined(_INC_WINDOWSX)
  123. _WCRTLINK extern void _WCFAR *_fcalloc( size_t __n, size_t __size );
  124. #endif
  125. #if !defined(_ncalloc) || !defined(_INC_WINDOWSX)
  126. _WCRTLINK extern void _WCNEAR *_ncalloc( size_t __n, size_t __size );
  127. #endif
  128. _WCRTLINK extern void * _expand( void *__ptr, size_t __size );
  129. #if !defined(_fexpand) || !defined(_INC_WINDOWSX)
  130. _WCRTLINK extern void _WCFAR *_fexpand( void _WCFAR *__ptr, size_t __size );
  131. #endif
  132. #if !defined(_nexpand) || !defined(_INC_WINDOWSX)
  133. _WCRTLINK extern void _WCNEAR *_nexpand( void _WCNEAR *__ptr, size_t __size );
  134. #endif
  135. #if !defined(_ffree) || !defined(_INC_WINDOWSX)
  136. _WCRTLINK extern void _ffree( void _WCFAR *__ptr );
  137. #endif
  138. #if !defined(_fmalloc) || !defined(_INC_WINDOWSX)
  139. _WCRTLINK extern void _WCFAR * _fmalloc( size_t __size );
  140. #endif
  141. _WCRTLINK extern unsigned int _freect( size_t __size );
  142. _WCRTLINK extern void _WCHUGE *halloc( long __n, size_t __size );
  143. _WCRTLINK extern void hfree( void _WCHUGE * );
  144. #if !defined(_nfree) || !defined(_INC_WINDOWSX)
  145. _WCRTLINK extern void _nfree( void _WCNEAR *__ptr );
  146. #endif
  147. #if !defined(_nmalloc) || !defined(_INC_WINDOWSX)
  148. _WCRTLINK extern void _WCNEAR *_nmalloc( size_t __size );
  149. #endif
  150. #if !defined(_nrealloc) || !defined(_INC_WINDOWSX)
  151. _WCRTLINK extern void _WCNEAR *_nrealloc( void _WCNEAR *__ptr, size_t __size );
  152. #endif
  153. #if !defined(_frealloc) || !defined(_INC_WINDOWSX)
  154. _WCRTLINK extern void _WCFAR *_frealloc( void _WCFAR *__ptr, size_t __size );
  155. #endif
  156. _WCRTLINK extern size_t _msize( void *__ptr );
  157. #if !defined(_nmsize) || !defined(_INC_WINDOWSX)
  158. _WCRTLINK extern size_t _nmsize( void _WCNEAR *__ptr );
  159. #endif
  160. #if !defined(_fmsize) || !defined(_INC_WINDOWSX)
  161. _WCRTLINK extern size_t _fmsize( void _WCFAR *__ptr );
  162. #endif
  163. _WCRTLINK extern size_t _memavl( void );
  164. _WCRTLINK extern size_t _memmax( void );
  165. _WCRTLINK extern void * calloc( size_t __n, size_t __size );
  166. _WCRTLINK extern void free( void *__ptr );
  167. _WCRTLINK extern void * malloc( size_t __size );
  168. _WCRTLINK extern void * realloc( void *__ptr, size_t __size );
  169.  
  170. #if defined(_M_IX86)
  171. /* based heap function prototypes */
  172.  
  173. #define _NULLSEG ((__segment)0)
  174. #define _NULLOFF ((void __based(void) *)~0)
  175.  
  176. _WCRTLINK extern int _bfreeseg( __segment __seg );
  177. _WCRTLINK extern __segment _bheapseg( size_t size );
  178. _WCRTLINK extern void __based(void) *_bcalloc( __segment __seg, size_t __num, size_t __size );
  179. _WCRTLINK extern void __based(void) *_bexpand( __segment __seg, void __based(void) *__mem, size_t __size );
  180. _WCRTLINK extern void _bfree( __segment __seg, void __based(void) *__mem );
  181. _WCRTLINK extern int _bheapchk( __segment __seg );
  182. _WCRTLINK extern int _bheapmin( __segment __seg );
  183. _WCRTLINK extern int _bheapshrink( __segment __seg );
  184. _WCRTLINK extern int _bheapset( __segment __seg, unsigned int __fill );
  185. _WCRTLINK extern int _bheapwalk( __segment __seg, struct _heapinfo *__entry );
  186. _WCRTLINK extern void __based(void) *_bmalloc( __segment __seg, size_t __size );
  187. _WCRTLINK extern size_t _bmsize( __segment __seg, void __based(void) *__mem );
  188. _WCRTLINK extern void __based(void) *_brealloc( __segment __seg, void __based(void) *__mem, size_t __size );
  189. #endif
  190. #pragma pack(__pop);
  191. #ifdef __cplusplus
  192. };
  193. #endif
  194. #endif
  195.