Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
memory_data.h
1 // NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2 // software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3 // derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4 // or works. Modified works should carry a notice stating that you changed the software and should note the date and
5 // nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6 // source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7 // EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9 // WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10 // CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11 // THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12 // are solely responsible for determining the appropriateness of using and distributing the software and you assume
13 // all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14 // with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15 // operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16 // damage to property. The software developed by NIST employees is not subject to copyright protection within the
17 // United States.
18 
19 
20 #ifndef HEDGEHOG_MEMORY_DATA_H
21 #define HEDGEHOG_MEMORY_DATA_H
22 
23 #include <memory>
24 #include "abstract_memory_manager.h"
25 
27 namespace hh {
28 
49 template<class ManagedMemory>
50 class MemoryData : public std::enable_shared_from_this<MemoryData<ManagedMemory>> {
51  private:
53  public:
55  MemoryData() = default;
56 
58  virtual ~MemoryData() = default;
59 
63 
67 
69  void returnToMemoryManager() { this->memoryManager_->recycleMemory(this->shared_from_this()); }
70 
72  virtual void used() {};
73 
76  virtual bool canBeRecycled() { return true; }
77 
83  virtual void recycle() {};
84 };
85 }
86 #endif //HEDGEHOG_MEMORY_DATA_H
void recycleMemory(std::shared_ptr< MemoryData< ManagedMemory >> managedMemory)
Recycle memory.
AbstractMemoryManager< ManagedMemory > * memoryManager_
Link to the Memory Manager.
Definition: memory_data.h:52
MemoryData()=default
Default constructor.
Hedgehog main namespace.
Memory data interface to use a data type in a Memory manager (AbstractMemoryManager or StaticMemoryMa...
Definition: memory_data.h:50
void memoryManager(AbstractMemoryManager< ManagedMemory > *memoryManager)
Memory manager setter.
Definition: memory_data.h:66
virtual void recycle()
Mechanism to recycle data.
Definition: memory_data.h:83
virtual ~MemoryData()=default
Default destructor.
virtual bool canBeRecycled()
Accessor to test if the data can be recycle and sent bask to the Pool, true by default.
Definition: memory_data.h:76
AbstractMemoryManager< ManagedMemory > * memoryManager() const
Memory manager accessor.
Definition: memory_data.h:62
virtual void used()
Mechanism to update the state of the data.
Definition: memory_data.h:72
void returnToMemoryManager()
Return the data to the memory manager.
Definition: memory_data.h:69