hobbes
a language, embedded compiler, and runtime for efficient dynamic expression evaluation, data storage and analysis
region.H
Go to the documentation of this file.
1 
2 #ifndef HOBBES_UTIL_REGION_HPP_INCLUDED
3 #define HOBBES_UTIL_REGION_HPP_INCLUDED
4 
5 #include <string>
6 
7 namespace hobbes {
8 
9 struct mempage {
10  void* base;
11  unsigned int size;
12  unsigned int read;
14 };
15 
16 class region {
17 public:
18  region(unsigned int minPageSize, unsigned int initialFreePages = 1, unsigned int maxPageSize = /*1GB*/ 1*1024*1024*1024);
19  ~region();
20 
21  // allocate 'sz' bytes of memory
22  void* malloc(unsigned int sz);
23 
24  // deallocate all pages (make sure you're not holding any references after this)
25  void clear();
26 
27  // reset the page read pointer
28  // (this is logically equivalent to 'clear' but doesn't deallocate pages -- new allocations happen over old ones)
29  void reset();
30 
31  // inspect the state of this memory region
32  size_t allocated() const; // how much memory is allocated by this region in all?
33  size_t used() const; // how much of allocated memory is actually used?
34  size_t wasted() const; // how much of allocated memory is unavailable for use?
35 
36  std::string show() const;
37 
38  // support catastrophic self-destruct on memory caps
39  void abortAtMemCeiling(size_t);
40 private:
41  unsigned int minPageSize;
42  unsigned int maxPageSize;
43  unsigned int lastAllocPageSize;
44  bool abortOnOOM;
47 
50 
51  mempage* newpage(mempage* succ, unsigned int sz);
52  void allocpage(unsigned int sz);
53 
54  void freepage(mempage* p);
55  void freepages(mempage* p);
56 };
57 
58 }
59 
60 #endif
61 
Definition: region.H:9
bool abortOnOOM
Definition: region.H:44
unsigned int lastAllocPageSize
Definition: region.H:43
mempage * usedp
Definition: region.H:48
unsigned int read
Definition: region.H:12
unsigned int minPageSize
Definition: region.H:41
Definition: region.C:72
Definition: boot.H:7
void * malloc(YYSIZE_T)
mempage * succ
Definition: region.H:13
size_t maxTotalAllocation
Definition: region.H:45
std::string show(const Expr &e)
Definition: expr.C:19
unsigned int maxPageSize
Definition: region.H:42
Definition: region.C:74
Definition: region.C:73
size_t totalAllocation
Definition: region.H:46
static const size_t minPageSize
Definition: file.C:53
unsigned int size
Definition: region.H:11
static const size_t maxPageSize
Definition: file.C:54
Definition: region.H:16
void * base
Definition: region.H:10
mempage * freep
Definition: region.H:49