home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / qb / qbdos.lzh / MEMALLOC.BAS < prev    next >
BASIC Source File  |  1987-10-12  |  2KB  |  69 lines

  1. '*****************************************************************************
  2.  
  3. 'Copyright (c) 1987 Marcel Madonna
  4.  
  5. 'MEMALLOC.BAS is an example of the use of the memory management routines.
  6. '       To compile it, type:
  7.  
  8. '               qb memalloc /l qbdos.exe;
  9. '               link memalloc /cp:16000;
  10. '               del memalloc.obj
  11. '
  12. ' You may have to play with the /cp parameter if you don't have 640K on
  13. ' your computer
  14.  
  15.  
  16. ' Allocate 64K of memory - indicate that each array element will be
  17. ' 80 characters long
  18.  
  19.     MemSize% = 64
  20.     Array.Size% = 80
  21.  
  22.     Call DosMAllc(Block%, MemSize%, Array.Size%, Rc%)
  23.     If Rc% <> 0 then
  24.         Print "Error allocating memory: code ";Rc%
  25.         End
  26.     End if
  27.  
  28. ' Let's fill the array with consecutive numbers
  29.  
  30.     String.Out$ = Space$(Array.Size%)
  31.     Index% = 0
  32.     While Rc% = 0
  33.         Mid$(String.Out$,1,Len(Str$(Index%))) = Str$(Index%)
  34.         Call DosMPut(Block%, Index%, String.Out$, Rc%)
  35.         If Rc% <> 0 then
  36.             Print Rc%, "Memory array is filled with ";Index%;" records";
  37.         Else
  38.             Index% = Index% + 1
  39.         End if
  40.     Wend
  41.     Rc% = 0
  42.     Mem.Ubound% = Index%-1
  43.  
  44. ' Let's retrieve every element in the array and print it on the consloe
  45.  
  46.     String.Out$ = Space$(Array.Size%)
  47.     Index% = 0
  48.     While Rc% = 0
  49.         Call DosMGet(Block%, Index%, String.Out$, Rc%)
  50.         If Rc% <> 0 then
  51.             Print "All records have been re-read"
  52.         Else
  53.             Print String.out$
  54.             Index% = Index% + 1
  55.         End if
  56.     Wend
  57.  
  58. ' Finally, let's de-allocate the array
  59.  
  60.     Call DosMFree(0, Rc%)
  61.  
  62.  
  63.  
  64.  
  65. 'Call DosMInit(Array.Size%, Rc%)
  66.  
  67.  
  68.  
  69.