Lhogho  0.0.027
Defines | Functions
mems.c File Reference

Defines

#define DUMP_BUF_SIZE   128

Functions

void delete_mem (atom_t a)
 deletes mem atom
atom_t new_mem (uint_t size)
 creates a new mem atom
void dump_mem (atom_t a, int level)
 dumps mem atom

Define Documentation

#define DUMP_BUF_SIZE   128

Function Documentation

Parameters:
aatom to delete

Deletes the mem atom and deallocates memory used by it.

{
  DEUSE( ATOMS(a) );
  DEALLOC( MEMORY(a) ); 
  return_to_pool( &data_pool, a );
}
atom_t new_mem ( uint_t  size)
Parameters:
sizesize of memory to allocate
Returns:
mem atom

Creates a memory atom with reference count 1.

{
  atom_t a = take_from_pool( &data_pool );

  REF(a)      = 1;
  ID(a)       = MEM_ID;
  MEMORY(a)   = XALLOC( (size_t)size );
  ATOMS(a)    = empty_list;

  #ifdef SAFEMODE
    assert( MEMORY(a) );
  #endif //SAFEMODE

  #ifdef DEBUG_ATOM
    printf("<ATOM>  [%08x] mem={%d bytes}\n",(int)a,size);
  #endif //DEBUG_ATOM

  #ifdef ADVANCED
    stats[ID(a)].allocs++;
    if( stats[ID(a)].max<(stats[ID(a)].allocs-stats[ID(a)].deallocs) )
      stats[ID(a)].max=(stats[ID(a)].allocs-stats[ID(a)].deallocs);
    stats_free--;
  #endif //ADVANCED

  #ifdef DEBUG_RUNTIME_ATOMS
  if( running_compiled_code )
    {
      outter( TEXT("<RUNTIME> new  "), -1 );
      dump_atom_address( a );
      dump_atom( a, 1 );
      outter( TEXT("\n"), -1 );
    }
  #endif
  #ifdef DEBUG_COMPILETIME_ATOMS
  if( compiling_code )
    {
      outter( TEXT("<COMPILETIME> new  "), -1 );
      dump_atom_address( a );
      dump_atom( a, 1 );
      outter( TEXT("\n"), -1 );
    }
  #endif

  return a;
}
void dump_mem ( atom_t  a,
int  level 
)
Parameters:
aatom to dump
leveldump level

Dumps mem through the current outter function.

{
  #define DUMP_BUF_SIZE 128
  char_t buf[DUMP_BUF_SIZE];
  int n;

  n = SPRINTF( buf, DUMP_BUF_SIZE, FORMAT_MEM, (int)MEMORY(a) );

  outter( buf, n );

  #undef DUMP_BUF_SIZE
}

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Tue Feb 7 2012