winheap.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. FPC Pascal system unit for the Win32 API.
  5. Copyright (c) 1998 by Florian Klaempfl and Pavel Ozerski
  6. member of the Free Pascal development team.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. type
  14. errproc=function(size:longint):integer;
  15. procedure MemError(size:longint);
  16. const
  17. message:array[1..21]of char=(
  18. 'A','b','n','o','r','m','a','l',' ',
  19. 'T','e','r','m','i','n','a','t','i','o','n',#0);
  20. caption:array[1..25]of char=(
  21. 'M','e','m','o','r','y',' ',
  22. 'M','a','n','a','g','e','m','e','n','t',' ',
  23. 'E','r','r','o','r','!',#0);
  24. var
  25. res:integer;
  26. begin
  27. repeat
  28. res:=errproc(heaperror)(size);
  29. if res=0 then
  30. begin;
  31. messagebox(0,@caption,@message,$10);
  32. halt(getlasterror);
  33. end;
  34. until res<>2;
  35. end;
  36. procedure getmem(var p:pointer;size:longint);[public,alias: 'GETMEM'];
  37. begin
  38. p:=GlobalLock(GlobalAlloc(258,size));
  39. if p=nil then
  40. memerror(size)
  41. end;
  42. procedure freemem(var p:pointer;size:longint);[public,alias: 'FREEMEM'];
  43. var
  44. h:longint;
  45. begin
  46. h:=GlobalHandle(p);
  47. if h<>0 then
  48. if globalunlock(h)=0 then
  49. if GlobalFree(h)=0 then
  50. begin
  51. p:=nil;
  52. exit{allways if success!!!}
  53. end;
  54. p:=nil;
  55. memerror(size);
  56. end;
  57. function memmax(_maxavail:boolean):longint;
  58. const
  59. status:record
  60. dwLength,
  61. dwMemoryLoad,
  62. dwTotalPhys,
  63. dwAvailPhys,
  64. dwTotalPageFile,
  65. dwAvailPageFile,
  66. dwTotalVirtual,
  67. dwAvailVirtual:longint;
  68. end=(dwLength:32);
  69. begin
  70. GlobalMemoryStatus(@status);
  71. if _maxavail then
  72. memmax:=status.dwAvailPageFile
  73. else
  74. memmax:=status.dwAvailVirtual;
  75. end;
  76. function memavail:longint;
  77. begin
  78. memavail:=memmax(false);
  79. end;
  80. function maxavail:longint;
  81. begin
  82. maxavail:=memmax(true);
  83. end;
  84. function growheap(size:longint):integer;
  85. begin
  86. growheap:=0;
  87. end;
  88. {
  89. $Log$
  90. Revision 1.2 1998-05-06 12:37:22 michael
  91. + Removed log from before restored version.
  92. Revision 1.1.1.1 1998/03/25 11:18:47 root
  93. * Restored version
  94. }