Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
mems.c
Go to the documentation of this file.
1 //
2 // Project: Lhogho
3 // File: mems.c
4 //
5 // Copyright (C) 2007 P.Boytchev
6 //
7 // Revision history:
8 // 2007-06-19 - file created from atoms.c
9 //
10 //
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 //
25 
26 
27 
28 
29 
30 #include <errno.h> // errno, ENOMEM
31 #include <assert.h>
32 #include <stdio.h>
33 #include <stdlib.h> // malloc()
34 
35 #include "atoms.h"
36 #include "pools.h"
37 #include "options.h"
38 #include "mems.h"
39 #include "unicode.h"
40 #include "lists.h"
41 #include "atoms.h"
42 #include "vars.h"
43 #include "compiler.h"
44 #include "numbers.h"
45 
46 
47 
48 //===================================================
55 //===================================================
56 void delete_mem( atom_t a )
57 {
58  DEUSE( ATOMS(a) );
59  DEALLOC( MEMORY(a) );
61 }
62 
63 
64 
65 
66 //===================================================
73 //===================================================
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 }
119 
120 
121 
122 
123 //===================================================
130 //===================================================
131 void dump_mem( atom_t a, int level )
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 }
143 
144 
145 
146 

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