Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
mems.c File Reference

Go to the source code of this file.

Macros

#define DUMP_BUF_SIZE   128
 

Functions

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

Macro Definition Documentation

#define DUMP_BUF_SIZE   128

Function Documentation

void delete_mem ( atom_t  a)
Parameters
aatom to delete

Deletes the mem atom and deallocates memory used by it.

Definition at line 56 of file mems.c.

57 {
58  DEUSE( ATOMS(a) );
59  DEALLOC( MEMORY(a) );
61 }
atom_t new_mem ( uint_t  size)
Parameters
sizesize of memory to allocate
Returns
mem atom

Creates a memory atom with reference count 1.

Definition at line 74 of file mems.c.

75 {
77 
78  REF(a) = 1;
79  ID(a) = MEM_ID;
80  MEMORY(a) = XALLOC( (size_t)size );
81  ATOMS(a) = empty_list;
82 
83  #ifdef SAFEMODE
84  assert( MEMORY(a) );
85  #endif //SAFEMODE
86 
87  #ifdef DEBUG_ATOM
88  printf("<ATOM> [%08x] mem={%d bytes}\n",(int)a,size);
89  #endif //DEBUG_ATOM
90 
91  #ifdef ADVANCED
92  stats[ID(a)].allocs++;
93  if( stats[ID(a)].max<(stats[ID(a)].allocs-stats[ID(a)].deallocs) )
94  stats[ID(a)].max=(stats[ID(a)].allocs-stats[ID(a)].deallocs);
95  stats_free--;
96  #endif //ADVANCED
97 
98  #ifdef DEBUG_RUNTIME_ATOMS
100  {
101  outter( TEXT("<RUNTIME> new "), -1 );
102  dump_atom_address( a );
103  dump_atom( a, 1 );
104  outter( TEXT("\n"), -1 );
105  }
106  #endif
107  #ifdef DEBUG_COMPILETIME_ATOMS
108  if( compiling_code )
109  {
110  outter( TEXT("<COMPILETIME> new "), -1 );
111  dump_atom_address( a );
112  dump_atom( a, 1 );
113  outter( TEXT("\n"), -1 );
114  }
115  #endif
116 
117  return a;
118 }
void dump_mem ( atom_t  a,
int  level 
)
Parameters
aatom to dump
leveldump level

Dumps mem through the current outter function.

Definition at line 131 of file mems.c.

132 {
133  #define DUMP_BUF_SIZE 128
134  char_t buf[DUMP_BUF_SIZE];
135  int n;
136 
137  n = SPRINTF( buf, DUMP_BUF_SIZE, FORMAT_MEM, (int)MEMORY(a) );
138 
139  outter( buf, n );
140 
141  #undef DUMP_BUF_SIZE
142 }

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013