Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

alloc.c File Reference

#include "c.h"

Include dependency graph for alloc.c:

Include dependency graph

Go to the source code of this file.

Data Structures

union  align
struct  block
union  header

Functions

void * allocate (unsigned long n, unsigned a)
void deallocate (unsigned a)
void * newarray (unsigned long m, unsigned long n, unsigned a)

Variables

block first []
blockfreeblocks


Function Documentation

void* allocate unsigned long  n,
unsigned  a
 

Definition at line 53 of file alloc.c.

References a, assert, block::avail, error(), exit(), freeblocks, block::limit, m, malloc(), n, NELEMS, block::next, and roundup.

Referenced by appendstr(), newarray(), prof_init(), and stringn().

00053                                             {
00054     struct block *ap;
00055 
00056     assert(a < NELEMS(arena));
00057     assert(n > 0);
00058     ap = arena[a];
00059     n = roundup(n, sizeof (union align));
00060     while (n > ap->limit - ap->avail) {
00061         if ((ap->next = freeblocks) != NULL) {
00062             freeblocks = freeblocks->next;
00063             ap = ap->next;
00064         } else
00065             {
00066                 unsigned m = sizeof (union header) + n + roundup(10*1024, sizeof (union align));
00067                 ap->next = malloc(m);
00068                 ap = ap->next;
00069                 if (ap == NULL) {
00070                     error("insufficient memory\n");
00071                     exit(1);
00072                 }
00073                 ap->limit = (char *)ap + m;
00074             }
00075         ap->avail = (char *)((union header *)ap + 1);
00076         ap->next = NULL;
00077         arena[a] = ap;
00078 
00079     }
00080     ap->avail += n;
00081     return ap->avail - n;
00082 }

Here is the call graph for this function:

void deallocate unsigned  a  ) 
 

Definition at line 87 of file alloc.c.

References a, assert, first, freeblocks, NELEMS, and block::next.

Referenced by initializer(), main(), program(), statement(), and walk().

00087                             {
00088     assert(a < NELEMS(arena));
00089     arena[a]->next = freeblocks;
00090     freeblocks = first[a].next;
00091     first[a].next = NULL;
00092     arena[a] = &first[a];
00093 }

void* newarray unsigned long  m,
unsigned long  n,
unsigned  a
 

Definition at line 84 of file alloc.c.

References a, allocate(), m, and n.

00084                                                              {
00085     return allocate(m*n, a);
00086 }

Here is the call graph for this function:


Variable Documentation

struct block first[] [static]
 

Initial value:

 {  { NULL },  { NULL },  { NULL } }
    *arena[] = { &first[0], &first[1], &first[2] }

Definition at line 49 of file alloc.c.

struct block* freeblocks [static]
 

Definition at line 51 of file alloc.c.

Referenced by allocate(), and deallocate().


Generated on Thu Aug 25 15:49:34 2005 for Quake III Arena by  doxygen 1.3.9.1