A smart-pointer that automatically creates and manages the lifetime of a shared static instance of a class.
More...
template<typename SharedObjectType>
class SharedResourcePointer< SharedObjectType >
A smart-pointer that automatically creates and manages the lifetime of a shared static instance of a class.
The SharedObjectType template type indicates the class to use for the shared object - the only requirements on this class are that it must have a public default constructor and destructor.
The SharedResourcePointer offers a pattern that differs from using a singleton or static instance of an object, because it uses reference-counting to make sure that the underlying shared object is automatically created/destroyed according to the number of SharedResourcePointer objects that exist. When the last one is deleted, the underlying object is also immediately destroyed. This allows you to use scoping to manage the lifetime of a shared resource.
Note: The construction/deletion of the shared object must not involve any code that makes recursive calls to a SharedResourcePointer, or you'll cause a deadlock.
Example:
struct MySharedData
{
MySharedData()
{
sharedStuff = generateHeavyweightStuff();
}
};
struct DataUserClass
{
DataUserClass()
{
useSharedStuff (sharedData->sharedStuff);
}
};
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:71
A smart-pointer that automatically creates and manages the lifetime of a shared static instance of a ...
Definition juce_SharedResourcePointer.h:97