HDK
|
#include <UT_MemoryResource.h>
Public Member Functions | |
bool | registerClient (UT_MemoryClient *client, UT_MemoryClient::Niceness niceness) |
Register as a client of the memory resource. More... | |
bool | registerClient (UT_MemoryClient *client, const UT_Array< UT_MemoryClient::Niceness > &niceness) |
bool | unregisterClient (UT_MemoryClient *client) |
Remove 'client' from this memory resource. More... | |
exint | requestMemoryFree (exint size_in_bytes, const UT_MemoryClient *from_client, UT_MemoryClient::RequestSeverity severity=UT_MemoryClient::NORMAL_REQUEST) |
void | returnMemory (const UT_MemoryClient *returning_client, exint size_in_bytes) |
exint | totalMemory () const |
Total amount of memory in the resource (bytes). More... | |
exint | usedMemory () |
const UT_StringMap< std::pair < UT_MemoryClient *, int > > | clients () const |
exint freeDeviceMemory(); More... | |
void | setTotalMemory (exint mem_in_bytes) |
Set the total amount of memory the resource has. More... | |
UT_MemoryResource (const UT_StringHolder &name, PassKey) | |
Static Public Member Functions | |
static const UT_StringHolder & | registerDeviceName (const UT_StringHolder &name, const uint8(&uuid)[16]) |
static bool | hasMemoryResource (const UT_StringHolder &name, UT_MemoryResource **mem=nullptr) |
Query if a named memory resource exists, optionally returning it. More... | |
static UT_MemoryResource * | getMemoryResource (const UT_StringHolder &name) |
Find a memory resource and create if it does not exist. More... | |
static const UT_StringMap < UT_UniquePtr < UT_MemoryResource > > & | memoryResources () |
List of memory resources. More... | |
Additional Inherited Members | |
![]() | |
UT_NonCopyable ()=default | |
~UT_NonCopyable ()=default | |
UT_NonCopyable (const UT_NonCopyable &)=delete | |
UT_NonCopyable & | operator= (const UT_NonCopyable &)=delete |
A named resource that represents a limited memory pool shared by several clients.
Definition at line 86 of file UT_MemoryResource.h.
UT_MemoryResource::UT_MemoryResource | ( | const UT_StringHolder & | name, |
PassKey | |||
) |
|
inline |
exint freeDeviceMemory();
Query the device directly for free memory. Due to other applications, this will likely be less than 'totalMemory()-usedMemory()'
Definition at line 151 of file UT_MemoryResource.h.
|
static |
Find a memory resource and create if it does not exist.
|
static |
Query if a named memory resource exists, optionally returning it.
|
static |
List of memory resources.
bool UT_MemoryResource::registerClient | ( | UT_MemoryClient * | client, |
UT_MemoryClient::Niceness | niceness | ||
) |
Register as a client of the memory resource.
bool UT_MemoryResource::registerClient | ( | UT_MemoryClient * | client, |
const UT_Array< UT_MemoryClient::Niceness > & | niceness | ||
) |
Register as a client of the memory resource but with several levels of 'niceness'. In this case, the client may have some higher priority data which it would rather hold onto, and some lower priority data which can be readily freed. This allows other clients to fulfill the free request at a lower priority level first, so that freeing the higher priority data may be avoided or reduced.
|
static |
Register a unqiue memory device, with a name and unique identifier. Returns a unique name based on the given name. If another device was already registered with the uuid, will return the same name used for it
exint UT_MemoryResource::requestMemoryFree | ( | exint | size_in_bytes, |
const UT_MemoryClient * | from_client, | ||
UT_MemoryClient::RequestSeverity | severity = UT_MemoryClient::NORMAL_REQUEST |
||
) |
Request that other clients of the memory resource free up memory. The 'from_client' parm is used to avoid the resource calling that client to free memory. The 'severity' is a hint to other clients. FATAL should be used only in cases where not respecting the request will result in app termination, so very sparingly.
void UT_MemoryResource::returnMemory | ( | const UT_MemoryClient * | returning_client, |
exint | size_in_bytes | ||
) |
Notify other clients that 'returning_client' is freeing up 'size_in_bytes' of the resource. This doesn't have to be called constantly, but after large deallocations, it may be helpful to notify the other clients.
Set the total amount of memory the resource has.
Definition at line 155 of file UT_MemoryResource.h.
exint UT_MemoryResource::totalMemory | ( | ) | const |
Total amount of memory in the resource (bytes).
bool UT_MemoryResource::unregisterClient | ( | UT_MemoryClient * | client | ) |
Remove 'client' from this memory resource.
exint UT_MemoryResource::usedMemory | ( | ) |
The amount of memory currently used by clients (bytes). This calls into all clients and asks them for their memory use, so use sparingly.