home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / E / TFF-A32R.LZX / AmigaE3.2a / RkrmSrc / Exec_Library / Memory / allocentry.e < prev   
Encoding:
Text File  |  1996-08-29  |  1.4 KB  |  44 lines

  1. -> allocentry.e - Example of allocating several memory areas.
  2.  
  3. MODULE 'exec/memory'
  4.  
  5. CONST ALLOCERROR=$80000000
  6.  
  7. -> E-Note: like the Assembly version, a ml does not contain a me, so body[4]
  8. OBJECT memBlocks
  9.   head:ml              -> One entry in the header, additional entries follow
  10.   body[4]:ARRAY OF me  -> directly as part of the same data structure
  11. ENDOBJECT
  12.  
  13. DEF memlist:PTR TO ml,  -> Pointer to a ml object
  14.     memblocks:memBlocks
  15.  
  16. PROC main()
  17.   memblocks.head.numentries:=4  -> E-Note: The ml does not contain another me!
  18.  
  19.   -> Describe the first piece of memory we want.
  20.   -> E-Note: every me is in the body, unlike the C version
  21.   memblocks.body[0].reqs:=MEMF_CLEAR
  22.   memblocks.body[0].length:=4000
  23.  
  24.   -> Describe the other pieces of memory we want.  Additional me's are
  25.   -> initialised this way.  If we wanted even more entries, we would need to
  26.   -> declare a larger me array in our memBlocks object.
  27.   memblocks.body[1].reqs:=MEMF_CHIP OR MEMF_CLEAR
  28.   memblocks.body[1].length:=100000
  29.   memblocks.body[2].reqs:=MEMF_PUBLIC OR MEMF_CLEAR
  30.   memblocks.body[2].length:=200000
  31.   memblocks.body[3].reqs:=MEMF_PUBLIC
  32.   memblocks.body[3].length:=25000
  33.  
  34.   memlist:=AllocEntry(memblocks)
  35.  
  36.   IF memlist AND ALLOCERROR  -> 'error' bit 31 is set (see below).
  37.     WriteF('AllocEntry FAILED\n')
  38.   ENDIF
  39.  
  40.   -> We got all memory we wanted.  Use it and call FreeEntry() to free it
  41.   WriteF('AllocEntry succeeded - now freeing all allocated blocks\n')
  42.   FreeEntry(memlist)
  43. ENDPROC
  44.