Datei: p7-5.c


    1   /*
    2    *      p7-5.c
    3    *      Beispielprogramm 5, Abschnitt 7
    4    *      Einfache Speicherverwaltung
    5    */
    6   
    7   #define NULL 0          /* Zeigerwert fuer Fehleranzeige */
    8   #define ALLOCSIZE 1000  /* verfuegbarer Platz */
    9   
   10   static char allocbuf[ALLOSIZE];
   11   static char *allocp = allocbuf; /* naechste freie Position */
   12   
   13   /* liefert Zeiger auf Platz fuer n Zeichen */
   14   char *alloc(int n)
   15   {
   16     if (allocp + n <= allocbuf + ALLOCSIZE) {     /* reicht */
   17       allocp += n;
   18       return (allocp - n);        /* alter Zeiger */
   19     } 
   20     else                          /* nicht genug Platz */
   21       return (NULL);
   22   
   23   } /* alloc() */
   24   
   25   /* Speicher ab p freigeben */
   26   void free(char *p) 
   27   {
   28     if (p >= allocbuf && p <= allocbuf + ALLOCSIZE)
   29       allocp = p;
   30   
   31   } /* free() */


Erzeugt von c2html 1.01