Advertisement
captmicro

Unknown

Dec 31st, 2010
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. DWORD dwXmemLeaks = 0;
  2. void *dwXmemory = NULL;
  3. DWORD xmemleaks() { return dwXmemLeaks; }
  4. void xmemlock() { HeapLock(dwXmemory); }
  5. void xmemunlock() { HeapUnlock(dwXmemory); }
  6. BYTE xmemvalidate(void *ptr) { return (BYTE)HeapValidate(dwXmemory, 0, ptr); }
  7. DWORD xmemsize(void *ptr) { return (DWORD)HeapSize(dwXmemory, 0, ptr); }
  8. void *xalloc(DWORD dwSize)
  9. {
  10.     if (dwXmemory == NULL) dwXmemory = HeapCreate(0, 0, 0);
  11.     dwXmemLeaks++;
  12.     return HeapAlloc(dwXmemory, HEAP_ZERO_MEMORY, dwSize);
  13. }
  14. void *xrealloc(void *ptr, DWORD dwSize)
  15. {
  16.     return HeapReAlloc(dwXmemory, HEAP_ZERO_MEMORY, ptr, dwSize);
  17. }
  18. void xfree(void *ptr)
  19. {
  20.     dwXmemLeaks--;
  21.     HeapFree(dwXmemory, HEAP_ZERO_MEMORY, ptr);
  22.     if (dwXmemLeaks == 0) { HeapDestroy(dwXmemory); dwXmemory = NULL; }
  23.     return;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement