Windows NT 4.0 source code leak
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.

156 lines
3.6 KiB

5 years ago
  1. /*
  2. ** Copyright 1994, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. **
  17. ** Author: Eric Veach, July 1994.
  18. */
  19. #include <stdio.h>
  20. #include <glos.h>
  21. #include <GL/gl.h>
  22. #include "memalloc.h"
  23. #include "string.h"
  24. // mf!
  25. //#define MF_DEBUG 1
  26. #define MEM_DEBUG 1
  27. #ifdef MEM_DEBUG
  28. ULONG DbgPrint(PSZ Format, ...);
  29. #include "\nt\private\windows\gdi\opengl\client\debug.h"
  30. #endif
  31. static GLuint AllocCount = 0;
  32. static GLuint FreeCount = 0;
  33. static BOOL bFree = TRUE;
  34. extern GLuint EdgeAlloc;
  35. extern GLuint VertexAlloc;
  36. extern GLuint FaceAlloc;
  37. extern GLuint MeshAlloc;
  38. extern GLuint RegionAlloc;
  39. extern GLuint EdgeFree;
  40. extern GLuint VertexFree;
  41. extern GLuint FaceFree;
  42. extern GLuint MeshFree;
  43. extern GLuint RegionFree;
  44. void mfmemInit( size_t maxFast )
  45. {
  46. #ifdef MF_DEBUG
  47. DBGPRINT1( "Init %p\n", maxFast );
  48. #endif
  49. #ifndef NO_MALLOPT
  50. mallopt( M_MXFAST, maxFast );
  51. #ifdef MEMORY_DEBUG
  52. mallopt( M_DEBUG, 1 );
  53. #endif
  54. #endif
  55. //#ifdef MF_DEBUG
  56. #if 1
  57. DBGPRINT2( "AllocCount = %d, FreeCount = %d\n", AllocCount, FreeCount );
  58. DBGPRINT2( "EdgeAlloc = %d, EdgeFree = %d\n", EdgeAlloc, EdgeFree );
  59. DBGPRINT2( "VertexAlloc = %d, VertexFree = %d\n", VertexAlloc, VertexFree );
  60. DBGPRINT2( "FaceAlloc = %d, FaceFree = %d\n", FaceAlloc, FaceFree );
  61. DBGPRINT2( "MeshAlloc = %d, MeshFree = %d\n", MeshAlloc, MeshFree );
  62. DBGPRINT2( "RegionAlloc = %d, RegionFree = %d\n", RegionAlloc, RegionFree );
  63. #endif
  64. AllocCount = 0;
  65. FreeCount = 0;
  66. EdgeAlloc = EdgeFree = VertexAlloc = VertexFree = FaceAlloc = FaceFree = 0;
  67. MeshAlloc = MeshFree = 0;
  68. RegionAlloc = RegionFree = 0;
  69. }
  70. void *mfmemAlloc( size_t size )
  71. {
  72. void *p;
  73. p = (void *) LocalAlloc(LMEM_FIXED, (UINT)(size));
  74. #ifdef MF_DEBUG
  75. DBGPRINT2( "Alloc %p, %d\n", p, size );
  76. #endif
  77. AllocCount++;
  78. return p;
  79. }
  80. void *mfmemRealloc( void *p, size_t size )
  81. {
  82. p = (void *) LocalReAlloc((HLOCAL)(p), (UINT)(size), LMEM_MOVEABLE);
  83. #ifdef MF_DEBUG
  84. DBGPRINT2( "Realloc %p, %d\n", p, size );
  85. #endif
  86. return p;
  87. }
  88. void mfmemFree( void *p )
  89. {
  90. #ifdef MF_DEBUG
  91. DBGPRINT1( "Free %p\n", p );
  92. #endif
  93. if( bFree )
  94. LocalFree((HLOCAL)(p));
  95. FreeCount++;
  96. }
  97. //mf: calloc not appear to be used
  98. #if 0
  99. #define calloc(nobj, size) LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, (UINT)((nobj) * (size)))
  100. #endif
  101. /******************************Public*Routine******************************\
  102. * DbgPrint()
  103. *
  104. * go to the user mode debugger in checked builds
  105. *
  106. * Effects:
  107. *
  108. * Warnings:
  109. *
  110. * History:
  111. * 09-Aug-1994 -by- Eric Kutter [erick]
  112. * Wrote it.
  113. \**************************************************************************/
  114. #if DBG
  115. VOID DoRip(PSZ psz)
  116. {
  117. DbgPrint("GDI Assertion Failure: ");
  118. DbgPrint(psz);
  119. DbgPrint("\n");
  120. DbgBreakPoint();
  121. }
  122. ULONG
  123. DbgPrint(
  124. PCH DebugMessage,
  125. ...
  126. )
  127. {
  128. va_list ap;
  129. char buffer[256];
  130. va_start(ap, DebugMessage);
  131. vsprintf(buffer, DebugMessage, ap);
  132. OutputDebugStringA(buffer);
  133. va_end(ap);
  134. return(0);
  135. }
  136. #endif