GridFire v0.7.6rc4.0
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::engine::scratch::AbstractScratchPad Struct Referenceabstract

Abstract base struct for engine scratchpad memory. More...

#include <scratchpad_abstract.h>

Inheritance diagram for gridfire::engine::scratch::AbstractScratchPad:
[legend]

Public Member Functions

virtual ~AbstractScratchPad ()=default
 Virtual destructor for proper cleanup of derived classes.
 
virtual bool is_initialized () const =0
 Check whether the scratchpad has been properly initialized.
 
virtual std::unique_ptr< AbstractScratchPadclone () const =0
 Create a deep copy of this scratchpad.
 

Detailed Description

Abstract base struct for engine scratchpad memory.

AbstractScratchPad defines the interface for temporary working memory containers used by computational engines. Implementations should provide storage for intermediate results, cached values, or pre-allocated buffers that persist across multiple computational steps.

This interface enables polymorphic handling of different scratchpad types while ensuring proper resource management through virtual destruction and deep cloning capabilities.

Thread Safety
This interface is not thread-safe by design. Scratchpads are intended to be used as thread-local working memory. Each thread should operate on its own independent scratchpad instance. Use the clone() method to create separate copies for each thread in parallel execution contexts. Sharing a single scratchpad instance across multiple threads without external synchronization will result in undefined behavior.

Constructor & Destructor Documentation

◆ ~AbstractScratchPad()

virtual gridfire::engine::scratch::AbstractScratchPad::~AbstractScratchPad ( )
virtualdefault

Virtual destructor for proper cleanup of derived classes.

Ensures that resources held by concrete scratchpad implementations are properly released when the scratchpad is destroyed through a base class pointer.

Member Function Documentation

◆ clone()

virtual std::unique_ptr< AbstractScratchPad > gridfire::engine::scratch::AbstractScratchPad::clone ( ) const
nodiscardpure virtual

Create a deep copy of this scratchpad.

Produces an independent clone of the scratchpad, including all internal state and allocated memory. This is essential for parallel execution scenarios where each thread requires its own working memory.

Returns
A unique pointer to a newly allocated copy of this scratchpad.
Note
The returned clone should be fully independent; modifications to the clone must not affect the original, and vice versa.
Examples
std::unique_ptr<AbstractScratchPad> original = create_scratchpad();
// Create independent copies for parallel workers
std::vector<std::unique_ptr<AbstractScratchPad>> worker_scratches;
for (int i = 0; i < num_threads; ++i) {
worker_scratches.push_back(original->clone());
}

Implemented in gridfire::engine::scratch::AdaptiveEngineViewScratchPad, gridfire::engine::scratch::DefinedEngineViewScratchPad, gridfire::engine::scratch::GraphEngineScratchPad, and gridfire::engine::scratch::MultiscalePartitioningEngineViewScratchPad.

◆ is_initialized()

virtual bool gridfire::engine::scratch::AbstractScratchPad::is_initialized ( ) const
nodiscardpure virtual

Check whether the scratchpad has been properly initialized.

Derived classes should return true only after all necessary memory allocations and setup operations have been completed successfully.

Returns
true if the scratchpad is initialized and ready for use.
false if the scratchpad has not been initialized or initialization failed.
Examples
auto scratch = create_scratchpad();
if (!scratch->is_initialized()) {
throw std::runtime_error("Scratchpad not ready for computation");
}
Scratchpad memory management for computational engines.
Definition blob.h:69

Implemented in gridfire::engine::scratch::AdaptiveEngineViewScratchPad, gridfire::engine::scratch::DefinedEngineViewScratchPad, gridfire::engine::scratch::GraphEngineScratchPad, and gridfire::engine::scratch::MultiscalePartitioningEngineViewScratchPad.


The documentation for this struct was generated from the following file: