Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) Microsoft Corporation, 1997.
  4. //
  5. // alloc.h
  6. //
  7. // Global allocation macros and routines.
  8. //
  9. // History:
  10. // Mon Jun 02 16:53:42 1997 -by- Drew Bliss [drewb]
  11. // Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #ifndef __ALLOC_H__
  15. #define __ALLOC_H__
  16. #include <types.h>
  17. //
  18. // Usage notes:
  19. //
  20. // ALLOC is a direct replacement for malloc().
  21. // ALLOCZ allocates zero-filled memory.
  22. // REALLOC is a direct replacement for realloc().
  23. // FREE is a direct replacement for free().
  24. //
  25. // On debug builds these macros evaluate to calls to a memory-tracking
  26. // allocator. On free builds they make direct heap calls.
  27. // All of the rest of the allocation routines are built on top of the
  28. // above macros and so inherit their tracking capabilities.
  29. //
  30. // The basic allocation routines also provide a mechanism to randomly
  31. // cause allocations to fail via manipulation of the glRandomMallocFail
  32. // variable.
  33. //
  34. #if DBG
  35. extern long glRandomMallocFail;
  36. void * FASTCALL dbgAlloc(UINT nbytes, DWORD flags);
  37. void * FASTCALL dbgRealloc(void *mem, UINT nbytes);
  38. void FASTCALL dbgFree(void *mem);
  39. int FASTCALL dbgMemSize(void *mem);
  40. #define ALLOC(nbytes) dbgAlloc((nbytes), 0)
  41. #define ALLOCZ(nbytes) dbgAlloc((nbytes), HEAP_ZERO_MEMORY)
  42. #define REALLOC(mem, nbytes) dbgRealloc((mem), (nbytes))
  43. #define FREE(mem) dbgFree((mem))
  44. #else // DBG
  45. #define ALLOC(nbytes) HeapAlloc(GetProcessHeap(), 0, (nbytes))
  46. #define ALLOCZ(nbytes) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, \
  47. (nbytes))
  48. #define REALLOC(mem, nbytes) HeapReAlloc(GetProcessHeap(), 0, (mem), \
  49. (nbytes))
  50. #define FREE(mem) HeapFree(GetProcessHeap(), 0, (mem))
  51. #endif // DBG
  52. //
  53. // 32-byte aligned memory allocator.
  54. //
  55. void * FASTCALL AllocAlign32(UINT nbytes);
  56. void FASTCALL FreeAlign32(void *mem);
  57. //
  58. // Short-lived memory allocator. This allocator should be used
  59. // for relatively small allocations (<= 4K) that are only live for
  60. // a function or two.
  61. //
  62. BOOL FASTCALL InitTempAlloc(void);
  63. void * FASTCALL gcTempAlloc(__GLcontext *gc, UINT nbytes);
  64. void FASTCALL gcTempFree(__GLcontext *gc, void *mem);
  65. //
  66. // Allocator wrappers which automatically set the gc error on failure.
  67. // The wrappers don't currently do anything extra on frees but
  68. // having matching free calls allows for per-gc tracking if necessary.
  69. //
  70. // Internal worker function.
  71. void * FASTCALL gcAlloc(__GLcontext *gc, UINT nbytes, DWORD flags);
  72. #define GCALLOC(gc, nbytes) gcAlloc((gc), (nbytes), 0)
  73. #define GCALLOCZ(gc, nbytes) gcAlloc((gc), (nbytes), HEAP_ZERO_MEMORY)
  74. void * FASTCALL GCREALLOC(__GLcontext *gc, void *mem, UINT nbytes);
  75. #define GCFREE(gc, mem) FREE(mem)
  76. void * FASTCALL GCALLOCALIGN32(__GLcontext *gc, UINT nbytes);
  77. #define GCFREEALIGN32(gc, mem) FreeAlign32(mem)
  78. #endif // #ifndef __ALLOC_H__