Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
managed_memory.h
Go to the documentation of this file.
1
2// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
3// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
4// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
5// or works. Modified works should carry a notice stating that you changed the software and should note the date and
6// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
7// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
8// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
9// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
10// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
11// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
12// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
13// are solely responsible for determining the appropriateness of using and distributing the software and you assume
14// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
15// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
16// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
17// damage to property. The software developed by NIST employees is not subject to copyright protection within the
18// United States.
19
20
21#ifndef HEDGEHOG_MANAGED_MEMORY_H_
22#define HEDGEHOG_MANAGED_MEMORY_H_
23
24#pragma once
25
26#include <memory>
27
29
31namespace hh {
32
34class ManagedMemory : public std::enable_shared_from_this<ManagedMemory> {
35 private:
37 public:
39 ManagedMemory() = default;
40
42 virtual ~ManagedMemory() = default;
43
46 bool isMemoryManagerConnected() { return memoryManager_ != nullptr; }
47
50 [[nodiscard]] AbstractMemoryManager *memoryManager() const { return memoryManager_; }
51
55
59 if (memoryManager_) {
60 memoryManager_->recycleMemory(this->shared_from_this());
61 } else {
62 throw (std::runtime_error("The data you are trying to return is not linked to a memory manager."));
63 }
64 }
65
67 virtual void postProcess() {};
68
71 virtual bool canBeRecycled() { return true; }
72
78 virtual void clean() {};
79
84 virtual void preProcess() {};
85
86};
87}
88#endif //HEDGEHOG_MANAGED_MEMORY_H_
Hedgehog main namespace.
Abstraction used to manage an user type with a memory manager.
virtual bool canBeRecycled()
Accessor to test if the data can be cleaned and sent back to the Pool, true by default.
ManagedMemory()=default
Default constructor.
AbstractMemoryManager * memoryManager() const
Memory manager accessor.
bool isMemoryManagerConnected()
Test is a memory manager has been connected to the managed memory.
void returnToMemoryManager()
Return the data to the memory manager.
AbstractMemoryManager * memoryManager_
Link to the Memory Manager.
virtual void clean()
Mechanism to clean data.
virtual void preProcess()
Mechanism to pre process the data.
virtual ~ManagedMemory()=default
Default destructor.
virtual void postProcess()
Mechanism called by Hedgehog when the node returns the memory before it is tested for being recycled ...
void memoryManager(AbstractMemoryManager *memoryManager)
Memory manager setter.
Abstract Memory manager.
virtual void recycleMemory(std::shared_ptr< ManagedMemory > const &managedMemory)=0
Recycle memory.