home *** CD-ROM | disk | FTP | other *** search
- '*****************************************************************************
-
- 'Copyright (c) 1987 Marcel Madonna
-
- 'MEMALLOC.BAS is an example of the use of the memory management routines.
- '
- ' ********************* N O T E *************************
- '
- 'This program cannot be used from the DOS prompt without Microsoft
- 'QuickBasic V4.0 and a registered copy of QBWARE.
- '
- 'To compile it, at the DOS prompt type:
-
- ' bc memalloc;
- ' link /ex /noe memalloc,,,brun40 qbware;
- ' del memalloc.obj
- ' del memalloc.map
-
- 'To run it fromthe QuickBasic development environment, type:
- '
- ' qb memalloc /l qbware
- ' [Shift] + F5
- '*****************************************************************************
-
-
- ' Allocate 64K of memory - indicate that each array element will be
- ' 80 characters long
-
- CLS
- FreeSpace = FRE(-1)
- IF FreeSpace < 100000 THEN
- CLS
- PRINT " ...Not enough storage to demonstrate this program"
- PRINT " ...Terminating"
- END
- ELSE
- PRINT " ...Working"
- END IF
-
- Release = SETMEM(-80000)
-
- MemSize% = 64
- Array.Size% = 80
-
- CALL DosMAllc(Block%, MemSize%, Array.Size%, Rc%)
- IF Rc% <> 0 THEN
- PRINT "Error allocating memory: code "; Rc%
- END
- END IF
-
- ' Let's fill the array with consecutive numbers
-
- String.out$ = SPACE$(Array.Size%)
- Index% = 0
- WHILE Rc% = 0
- MID$(String.out$, 1, LEN(STR$(Index%))) = STR$(Index%)
- CALL DosMPut(Block%, Index%, String.out$, Rc%)
- IF Rc% <> 0 THEN
- PRINT Rc%, "Memory array is filled with "; Index%; " records";
- ELSE
- Index% = Index% + 1
- END IF
- WEND
- Rc% = 0
- Mem.Ubound% = Index% - 1
-
- ' Let's retrieve every element in the array and print it on the console
-
- String.out$ = SPACE$(Array.Size%)
- Index% = 0
- WHILE Rc% = 0
- CALL DosMGet(Block%, Index%, String.out$, Rc%)
- IF Rc% <> 0 THEN
- PRINT "All records have been re-read"
- ELSE
- PRINT String.out$
- Index% = Index% + 1
- END IF
- WEND
-
- ' Finally, let's de-allocate the array
-
- CALL DosMFree(0, Rc%)
-
- ' Return it to QB far heap
-
- Allocate = SETMEM(80000)
-
- END
-
-
-
-
-
-
-