HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_MemoryResource Class Reference

#include <UT_MemoryResource.h>

+ Inheritance diagram for UT_MemoryResource:

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_StringHolderregisterDeviceName (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_MemoryResourcegetMemoryResource (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

- Protected Member Functions inherited from UT_NonCopyableNS::UT_NonCopyable
 UT_NonCopyable ()=default
 
 ~UT_NonCopyable ()=default
 
 UT_NonCopyable (const UT_NonCopyable &)=delete
 
UT_NonCopyableoperator= (const UT_NonCopyable &)=delete
 

Detailed Description

A named resource that represents a limited memory pool shared by several clients.

Definition at line 86 of file UT_MemoryResource.h.

Constructor & Destructor Documentation

UT_MemoryResource::UT_MemoryResource ( const UT_StringHolder name,
PassKey   
)

Member Function Documentation

const UT_StringMap<std::pair<UT_MemoryClient *,int> > UT_MemoryResource::clients ( ) const
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 UT_MemoryResource* UT_MemoryResource::getMemoryResource ( const UT_StringHolder name)
static

Find a memory resource and create if it does not exist.

static bool UT_MemoryResource::hasMemoryResource ( const UT_StringHolder name,
UT_MemoryResource **  mem = nullptr 
)
static

Query if a named memory resource exists, optionally returning it.

static const UT_StringMap<UT_UniquePtr<UT_MemoryResource> >& UT_MemoryResource::memoryResources ( )
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 const UT_StringHolder& UT_MemoryResource::registerDeviceName ( const UT_StringHolder name,
const uint8(&)  uuid[16] 
)
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.

void UT_MemoryResource::setTotalMemory ( exint  mem_in_bytes)
inline

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.


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