Category : Miscellaneous Language Source Code
Archive   : STLTH22.ZIP
Filename : ALLOCBUF.PAS

 
Output of file : ALLOCBUF.PAS contained in archive : STLTH22.ZIP
{
allocbuf.pas
Stealth Bomber Version 2.2

Kevin Dean
Fairview Mall P.O. Box 55074
1800 Sheppard Avenue East
Willowdale, Ontario
CANADA M2J 5B9
CompuServe ID: 76336,3114

February 10, 1992

This module allocates a simple memory buffer whose size depends on the
amount of memory available. The size of the buffer is halved each time the
allocation fails until memory is successfully allocated or the size goes below
the minimum size requested.

This code is public domain.
}


unit AllocBuf;


interface


function BufAlloc(var Size : word; MinSize : word) : pointer;


implementation


{***}
{ Allocate a buffer of flexible size. }
function BufAlloc(var Size : word; MinSize : word) : pointer;

var
Buffer : pointer;
BufSize : word;

begin
{ Allocate as big a buffer as possible (at least MinSize). }
BufSize := Size;
repeat
GetMem(Buffer, BufSize);
if Buffer = nil then
BufSize := BufSize div 2;
until (Buffer <> nil) or (BufSize < MinSize);

{ Save buffer size. }
Size := BufSize;

BufAlloc := Buffer;
end;


end.


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : STLTH22.ZIP
Filename : ALLOCBUF.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/