home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / crc / crcset / allocbuf.pas next >
Encoding:
Pascal/Delphi Source File  |  1991-07-13  |  1.0 KB  |  59 lines

  1. {
  2. ALLOCBUF.PAS
  3.  
  4. Kevin Dean
  5. Fairview Mall P.O. Box 55074
  6. 1800 Sheppard Avenue East
  7. Willowdale, Ontario
  8. CANADA    M2J 5B9
  9. CompuServe ID: 76336,3114
  10.  
  11. March 24, 1991
  12.  
  13.     This module allocates a simple memory buffer whose size depends on the
  14. amount of memory available.  The size of the buffer is halved each time the
  15. allocation fails until memory is successfully allocated or the size goes below
  16. the minimum size requested.
  17.  
  18.     This code is public domain.
  19. }
  20.  
  21.  
  22. unit AllocBuf;
  23.  
  24.  
  25. interface
  26.  
  27.  
  28. function BufAlloc(var Size : word; MinSize : word) : pointer;
  29.  
  30.  
  31. implementation
  32.  
  33.  
  34. {***}
  35. { Allocate a buffer of flexible size. }
  36. function BufAlloc(var Size : word; MinSize : word) : pointer;
  37.  
  38. var
  39.   Buffer : pointer;
  40.   BufSize : word;
  41.  
  42. begin
  43. { Allocate as big a buffer as possible (at least MinSize). }
  44. BufSize := Size;
  45. repeat
  46.   GetMem(Buffer, BufSize);
  47.   if Buffer = nil then
  48.     BufSize := BufSize div 2
  49. until (Buffer <> nil) or (BufSize < MinSize);
  50.  
  51. { Save buffer size. }
  52. Size := BufSize;
  53.  
  54. BufAlloc := Buffer
  55. end;
  56.  
  57.  
  58. end.
  59.