home *** CD-ROM | disk | FTP | other *** search
- { MEMALLOC.PAS
- Demonstrates use of the Turbo Vision MemAlloc function.
- }
- Program DemoMemAlloc;
- uses
- Memory;
- label 99;
- var
- APointer : Pointer;
- I : Integer;
-
- function HeapFunc(Size : Word): Integer; far;
- { Returns 1 = force memory manager to return NIL on out of memory
- set to alternate values as shown:
- 0 = force a Heap Overflow error
- 2 = tells the memory manger to try again (for instance,
- you might dispose of some items in this routine, thereby
- freeing up some memory)
- }
- begin
-
- HeapFunc := 1;
-
- end;
-
-
- begin
- { Initialize the Heap Overflow checker }
- HeapError := @HeapFunc;
-
- { Allocate some blocks of memory until running out of free space.
- You may have to use a value higher than 20 or a larger block size }
- for i:=1 to 20 do
- begin
- APointer := MemAlloc(20000);
-
- writeln(longint(Apointer));
- if APointer = NIL then
- begin
- writeln('OUT OF MEMORY');
- Goto 99;
- end;
-
- Write('Press Enter to continue');
- readln;
- end;
-
- 99:
- Write('Program completed. Press Enter to continue');
- Readln;
-
- end.