home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 November / VPR9611B.ISO / vabasic / ntclnt.exe / DISK8 / data.8 / datab / INCLUDE / VEALLOC.H < prev    next >
C/C++ Source or Header  |  1996-07-29  |  5KB  |  149 lines

  1. /*------------------------------------------------------------------------
  2.  * $Source: /rcs/crcs/general/vealloc.h,v $
  3.  * Checked in by: $Author: jose $
  4.  * $Date: 1996/04/23 12:52:40 $                   $Revision: 1.3 $
  5.  *
  6.  * Copyright 1987, Techtrol Ltd.
  7.  * Copyright 1990, Visual Edge Software Ltd.
  8.  * -----------------------------------------
  9.  * ALL RIGHTS RESERVED.  This notice is intended as a precaution against
  10.  * inadvertent publication, and shall not be deemed to constitute an
  11.  * acknowledgment that publication has  occurred nor to imply any waiver
  12.  * of confidentiality.  The year included in the notice is the year
  13.  * of the creation of the work.
  14.  *------------------------------------------------------------------------*/
  15. /*------------------------------------------------------------------------
  16.  *
  17.  *         Module Name: valloc.h
  18.  *  Module Description: Declarations for general allocation routines.
  19.  *
  20.  *                Date: Unknown
  21.  *
  22.  *------------------------------------------------------------------------*/
  23. #ifndef _VEALLOC_INCLUDED
  24. #define _VEALLOC_INCLUDED
  25.  
  26. #include <stdio.h>
  27. #include <os.h>
  28. #include <visedge.h>    
  29.  
  30. #ifdef __cplusplus
  31. #define VECONST const
  32. extern "C" {
  33. #else
  34. #define VECONST
  35. #endif
  36.  
  37. extern VFUNCDECL(void*) VeMalloc   UXPROTO((size_t));
  38. extern VFUNCDECL(void*) VeCalloc   UXPROTO((size_t, size_t));
  39. extern VFUNCDECL(void*) VeRealloc  UXPROTO((void *, size_t));
  40. extern VFUNCDECL(void ) VeFree     UXPROTO((void *));
  41. extern VFUNCDECL(char*) VeCopyString UXPROTO(( char * ));
  42.  
  43. /* Definition of option parameters for VeMemAlloc, VeMemCalloc and VeMemRealloc.
  44.    These values specify how a memory crash is handled. 
  45.  
  46.     VRETURN_NOMEMORY: Tells the memory manager to return a NULL pointer to 
  47.              the caller if memory crash occurs (this option has 
  48.              precedence over VHANDLE_NOMEMORY). 
  49.     VHANDLE_NOMEMORY: Memory crash is handled by the memory manager, no 
  50.              pointer is returned to caller. The manager display an 
  51.              error message and aborts the application.
  52.     VVERBOSE:     Tells the memory manager to display an error message 
  53.              if a memory crash occurs.    
  54. */
  55.  
  56. #define VHANDLE_NOMEMORY    (1<<0)    
  57. #define VRETURN_NOMEMORY    (1<<1)
  58. #define VVERBOSE        (1<<2)
  59.     
  60. extern VFUNCDECL(void*) VeMemAlloc   UXPROTO((size_t, int));
  61. extern VFUNCDECL(void*) VeMemCalloc   UXPROTO((size_t, size_t, int));
  62. extern VFUNCDECL(void*) VeMemRealloc  UXPROTO((void *, size_t, int));
  63.  
  64. #ifdef VSYS_WINDOWS
  65.  
  66. #include <malloc.h>
  67.  
  68. #define UxStackAlloc(size)    _alloca((size) ? (size) : 4)
  69. #define UxStackFree(pntr)
  70.  
  71. #else /* VSYS_WINDOWS */
  72.  
  73. #define UxStackAlloc(size)    VeMalloc(size)
  74. #define UxStackFree(pntr)    VeFree(pntr)
  75.  
  76. #endif /* VSYS_WINDOWS */
  77.  
  78. #ifndef VSYS_NO_CLEANUP
  79. VFUNCDECL(void) VeFreeAllMemory();
  80. #endif
  81.  
  82. #if defined(MEMDEBUG) || defined(DEBUG)
  83.  
  84. typedef enum
  85. {
  86.     MemoryAlwaysCheck = 0,
  87.     MemoryPrintZero = 1,
  88.     MemoryCrash = 2,
  89.     MemoryFill = 3,
  90.     MemoryFree = 4
  91. } MemoryOption;
  92.  
  93. extern VFUNCDECL(void*) VeDebugMalloc   UXPROTO((size_t, VECONST char *, unsigned));
  94. extern VFUNCDECL(void*) VeDebugRealloc  UXPROTO((void *, size_t, VECONST char *, unsigned));
  95. extern VFUNCDECL(void*) VeDebugCalloc   UXPROTO((size_t, size_t, VECONST char *, unsigned));
  96. extern VFUNCDECL(void) VeDebugFree      UXPROTO((void *, VECONST char *, unsigned));
  97.  
  98. extern VFUNCDECL(char*) VeDebugCopyString UXPROTO((char *, VECONST char *, unsigned));
  99.  
  100. extern VFUNCDECL(void*) VeCheckMemory      UXPROTO(());
  101. extern VFUNCDECL(void) VeShowMemory        UXPROTO((FILE *fp));
  102. extern VFUNCDECL(void) VeDumpMemory        UXPROTO((VECONST char *fname));
  103. extern VFUNCDECL(void) VeSetMemoryRunOut   UXPROTO((unsigned long));
  104. extern VFUNCDECL(void) VeSetMemoryOption   UXPROTO((MemoryOption opt, int value));
  105.  
  106. #endif
  107.  
  108. #ifdef MEMDEBUG
  109.  
  110. #define VeMalloc(s)     VeDebugMalloc(s, __FILE__, __LINE__)
  111. #define VeRealloc(p, s) VeDebugRealloc(p, s, __FILE__, __LINE__)
  112. #define VeCalloc(s, n)  VeDebugCalloc(s, n, __FILE__, __LINE__)
  113. #define VeFree(p)       VeDebugFree(p, __FILE__, __LINE__)
  114.  
  115. #endif
  116.  
  117. /* Global function to change underlying memory allocation functions */
  118.  
  119. typedef void* VFUNCPTR(VTobAllocator)(size_t);
  120. typedef void* VFUNCPTR(VTobReallocator)(void*, size_t);
  121. typedef void  VFUNCPTR(VTobDeallocator)(void*);
  122.  
  123. extern VFUNCDECL(status_t) VePutInternalAllocator UXPROTO((
  124.             VTobAllocator, VTobReallocator, VTobDeallocator));
  125.  
  126.  
  127. #ifdef  __cplusplus
  128. }
  129.  
  130. #if defined(MEMDEBUG) && !defined(NOVIPERNEW)
  131.  
  132. VFUNCDECL(void*) operator new(size_t, const char *, unsigned);
  133.  
  134. #ifdef ANSIcplusplus
  135. void *operator new[](size_t, const char *, unsigned);
  136. #endif /* ANSIcplusplus */
  137.  
  138. #endif
  139.  
  140. /* Redefine the new operator for debugging support. */
  141. #include <defnew.hh>
  142.  
  143. #endif
  144.  
  145. #define UxNew(t)                (t *)VeCalloc(sizeof(t), 1)
  146. #define UxNewArray(t, v)        (t *)VeCalloc(sizeof(t), (v))
  147.  
  148. #endif /* _VEALLOC_INCLUDED */
  149.