sysheap.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005 by Free Pascal development team
  4. Low level memory functions
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { Enable this for memory allocation debugging }
  12. {DEFINE MOSFPC_MEMDEBUG}
  13. {*****************************************************************************
  14. OS Memory allocation / deallocation
  15. ****************************************************************************}
  16. function SysOSAlloc(size: ptruint): pointer;
  17. {$IFDEF MOSFPC_MEMDEBUG}
  18. var values: array[0..2] of dword;
  19. {$ENDIF}
  20. begin
  21. result:=AllocPooled(AOS_heapPool,size);
  22. {$IFDEF MOSFPC_MEMDEBUG}
  23. values[0]:=dword(result);
  24. values[1]:=dword(size);
  25. values[2]:=DWord(Sptr-StackBottom);
  26. RawDoFmt('FPC_MEM_DEBUG: $%lx:=SysOSAlloc(%ld), free stack: %ld bytes'+#10,@values,pointer(1),nil);
  27. {$ENDIF}
  28. end;
  29. {$define HAS_SYSOSFREE}
  30. procedure SysOSFree(p: pointer; size: ptruint);
  31. {$IFDEF MOSFPC_MEMDEBUG}
  32. var values: array[0..2] of dword;
  33. {$ENDIF}
  34. begin
  35. FreePooled(AOS_heapPool,p,size);
  36. {$IFDEF MOSFPC_MEMDEBUG}
  37. values[0]:=dword(p);
  38. values[1]:=dword(size);
  39. values[2]:=DWord(Sptr-StackBottom);
  40. RawDoFmt('FPC_MEM_DEBUG: SysOSFree($%lx,%ld), free stack: %ld bytes'+#10,@values,pointer(1),nil);
  41. {$ENDIF}
  42. end;