Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions
objalloc.h File Reference
#include "ansidecl.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  objalloc
struct  objalloc_align

Defines

#define offsetof(TYPE, MEMBER)   ((unsigned long) &((TYPE *)0)->MEMBER)
#define OBJALLOC_ALIGN   offsetof (struct objalloc_align, d)
#define objalloc_alloc(o, l)   _objalloc_alloc ((o), (l))

Functions

struct objallocobjalloc_create (void)
void * _objalloc_alloc (struct objalloc *, unsigned long)
void objalloc_free (struct objalloc *)
void objalloc_free_block (struct objalloc *, void *)

Class Documentation

struct objalloc

Definition at line 44 of file objalloc.h.

Class Members
void * chunks
char * current_ptr
unsigned int current_space
struct objalloc_align

Definition at line 53 of file objalloc.h.

Class Members
double d
char x

Define Documentation

Definition at line 63 of file objalloc.h.

#define objalloc_alloc (   o,
  l 
)    _objalloc_alloc ((o), (l))

Definition at line 102 of file objalloc.h.

#define offsetof (   TYPE,
  MEMBER 
)    ((unsigned long) &((TYPE *)0)->MEMBER)

Definition at line 61 of file objalloc.h.


Function Documentation

void* _objalloc_alloc ( struct objalloc ,
unsigned  long 
)

Definition at line 115 of file objalloc.c.

{
  /* We avoid confusion from zero sized objects by always allocating
     at least 1 byte.  */
  if (len == 0)
    len = 1;

  len = (len + OBJALLOC_ALIGN - 1) &~ (OBJALLOC_ALIGN - 1);

  if (len <= o->current_space)
    {
      o->current_ptr += len;
      o->current_space -= len;
      return (PTR) (o->current_ptr - len);
    }

  if (len >= BIG_REQUEST)
    {
      char *ret;
      struct objalloc_chunk *chunk;

      ret = (char *) malloc (CHUNK_HEADER_SIZE + len);
      if (ret == NULL)
       return NULL;

      chunk = (struct objalloc_chunk *) ret;
      chunk->next = (struct objalloc_chunk *) o->chunks;
      chunk->current_ptr = o->current_ptr;

      o->chunks = (PTR) chunk;

      return (PTR) (ret + CHUNK_HEADER_SIZE);
    }
  else
    {
      struct objalloc_chunk *chunk;

      chunk = (struct objalloc_chunk *) malloc (CHUNK_SIZE);
      if (chunk == NULL)
       return NULL;
      chunk->next = (struct objalloc_chunk *) o->chunks;
      chunk->current_ptr = NULL;

      o->current_ptr = (char *) chunk + CHUNK_HEADER_SIZE;
      o->current_space = CHUNK_SIZE - CHUNK_HEADER_SIZE;

      o->chunks = (PTR) chunk;

      return objalloc_alloc (o, len);
    }
}

Here is the call graph for this function:

struct objalloc* objalloc_create ( void  ) [read]

Definition at line 86 of file objalloc.c.

{
  struct objalloc *ret;
  struct objalloc_chunk *chunk;

  ret = (struct objalloc *) malloc (sizeof *ret);
  if (ret == NULL)
    return NULL;

  ret->chunks = (PTR) malloc (CHUNK_SIZE);
  if (ret->chunks == NULL)
    {
      free (ret);
      return NULL;
    }

  chunk = (struct objalloc_chunk *) ret->chunks;
  chunk->next = NULL;
  chunk->current_ptr = NULL;

  ret->current_ptr = (char *) chunk + CHUNK_HEADER_SIZE;
  ret->current_space = CHUNK_SIZE - CHUNK_HEADER_SIZE;

  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file objalloc.c.

{
  struct objalloc_chunk *l;

  l = (struct objalloc_chunk *) o->chunks;
  while (l != NULL)
    {
      struct objalloc_chunk *next;

      next = l->next;
      free (l);
      l = next;
    }

  free (o);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void objalloc_free_block ( struct objalloc ,
void *   
)

Here is the caller graph for this function: