ICG 2
Electric Boogaloo
MemoryManager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <map>
5 #include <string>
6 #include <pthread.h>
7 
8 #include "DataTypeInator.hpp"
10 #include "Type/DataType.hpp"
11 
13 
19 
20  public:
26  MemoryManager (DataTypeInator * dataTypeInator);
27 
28  ~MemoryManager ();
29 
30  // no copying
31  MemoryManager(const MemoryManager& other) = delete;
32 
40  void* declare_var( const std::string& declaration, void* suppliedAllocation = NULL);
41 
42 
43 
50  bool var_exists( const std::string& var_name);
51 
57  void clear_var( void* address);
58 
64  void clear_var( const std::string& var_name);
65 
70  void clear_all_vars();
71 
77  void delete_var(void* address);
78 
84  void delete_var(std::string var_name);
85 
91  void write_checkpoint( std::ostream& out_s);
92 
98  void write_checkpoint( const std::string& filename);
99 
105  void restore_checkpoint(const std::string& filename);
106 
112  void restore_checkpoint( std::istream& in_s);
113 
120  AllocInfo* getAllocInfoOf( void* address );
121 
128  AllocInfo* getAllocInfoAt( void* address );
129 
136  AllocInfo* getAllocInfoNamed( const std::string& name );
137 
144  std::shared_ptr<const DataType> getDataTypeOf(const std::string& name);
145 
152 
153  private:
154 
155  void do_write_checkpoint(std::ostream& outStream, std::vector<AllocInfo*>& dependencies);
156 
157  void* do_declare_var(const std::string& abstract_declarator,
158  const std::string& variable_name,
159  void * supplied_allocation);
160 
161  void delete_allocation(AllocInfo * allocInfo);
162 
163  unsigned int debugLevel;
164 
165  CheckpointAgentBase * checkpointAgent;
166  DataTypeInator* dataTypeInator;
167 
168  // TODO: Let's think about this.
169  // I would like to switch to c++ threading instead using pthreads directly
170  pthread_mutex_t allocInfoMapMutex;
171 
172  std::map<void*, AllocInfo*> allocInfoByAddressMap;
173  std::map<std::string, AllocInfo*> allocInfoByNameMap;
174 
175 };
Definition: AllocInfo.hpp:33
Definition: NewCheckpointAgentBase.hpp:13
Register and manage datatypes at runtime.
Definition: DataTypeInator.hpp:16
Keep track of allocations and their type.
Definition: MemoryManager.hpp:18
MemoryManager(const MemoryManager &other)=delete
AllocInfo * getAllocInfoNamed(const std::string &name)
Get the AllocInfo with the given name.
Definition: MemoryManager.cpp:256
void setCheckPointAgent(CheckpointAgentBase *agent)
Set the CheckPointAgent.
Definition: MemoryManager.cpp:226
void * declare_var(const std::string &declaration, void *suppliedAllocation=NULL)
Declare a new allocation of given type with the memory manager.
Definition: MemoryManager.cpp:64
bool var_exists(const std::string &var_name)
Check if a variable is registered with the memory manager.
Definition: MemoryManager.cpp:75
std::shared_ptr< const DataType > getDataTypeOf(const std::string &name)
Get the DataType of the given variable.
Definition: MemoryManager.cpp:268
void delete_var(void *address)
Delete the variable.
Definition: MemoryManager.cpp:115
void clear_var(void *address)
Clear the value at the given address, if it is registered with the memorymanager.
Definition: MemoryManager.cpp:87
AllocInfo * getAllocInfoOf(void *address)
Get the AllocInfo that contains the given address.
Definition: MemoryManager.cpp:232
void restore_checkpoint(const std::string &filename)
Restore a checkpoint from file with given name.
Definition: MemoryManager.cpp:181
void clear_all_vars()
Clear all variables registered with the memory manager.
Definition: MemoryManager.cpp:109
MemoryManager(DataTypeInator *dataTypeInator)
Construct a new Memory Manager.
Definition: MemoryManager.cpp:16
AllocInfo * getAllocInfoAt(void *address)
Get the AllocInfo that starts at the given address.
Definition: MemoryManager.cpp:245
~MemoryManager()
Definition: MemoryManager.cpp:23
void write_checkpoint(std::ostream &out_s)
Write checkpoint to an output stream.
Definition: MemoryManager.cpp:159