home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / exec / memory / allocentry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  2.9 KB  |  80 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /* Compiled with Lattice C 5.04: LC -b1 -cfist -v -y
  23.  * Linkage: blink from lib:c.o+allocentry.o to allocentry lib lib:lc.lib lib:amiga.lib
  24.  */
  25.  
  26. #include <exec/types.h>
  27. #include <exec/memory.h>
  28.  
  29. #ifdef LATTICE
  30. #include <proto/all.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #endif
  34.  
  35. #define ALLOCERROR 0x80000000
  36.  
  37. struct MemList *mymemlist;       /* pointer to a MemList */
  38.  
  39. /* define a new structure because C cannot initialize unions */
  40. struct MyNeeds
  41. {
  42.     struct MemList  mn_head;     /* one entry in the header */
  43.     struct MemEntry mn_body[3];  /* additional entries follow directly as *
  44.                                   * part of the same data structure       */
  45. } myneeds;
  46.  
  47. VOID main (VOID);
  48.  
  49. VOID main(VOID)
  50. {
  51.     myneeds.mn_head.ml_NumEntries = 4; /* 4! Since the MemEntry starts at 1! */
  52.     
  53.     myneeds.mn_body[0].me_Reqs   = MEMF_CHIP | MEMF_CLEAR;
  54.     myneeds.mn_body[0].me_Length = 100000;
  55.  
  56.     myneeds.mn_body[1].me_Reqs   = MEMF_FAST | MEMF_CLEAR;
  57.     myneeds.mn_body[1].me_Length = 200000;
  58.  
  59.     myneeds.mn_body[2].me_Reqs   = MEMF_PUBLIC;
  60.     myneeds.mn_body[2].me_Length = 25000;
  61.  
  62.     /* saying 'struct MemEntry mn_body[3]' is simply a way of adding
  63.      * extra MemEntry structures contiguously at the end of the first
  64.      * such structure at the ned of the MemList. Thus members of the
  65.      * MemList of type MemEntry can be referenced to in C as additional
  66.      * members of the 'me[]' data structure.
  67.      */
  68.  
  69.     mymemlist = (struct MemList *)AllocEntry((struct MemList *)&myneeds);
  70.  
  71.     if ((ULONG)mymemlist & ALLOCERROR)
  72.     {                                     /* 'error' bit 31 is set */
  73.        printf("AllocEntry FAILED\n");    /*       see below       */
  74.        exit(200);
  75.     }
  76.  
  77.     /* we got the memory we wanted. We can use FreeEntry() now */
  78.     FreeEntry(mymemlist);
  79. }
  80.