InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IMemoryManager Class Referenceabstract

#include <IMemoryManager.h>

Inheritance diagram for IMemoryManager:
IPMUnknown

Public Types

enum  { kDefaultIID = IID_IMEMORYMANAGER }
 
enum  PurgeLevel {
  kNoPurge = -1, kSwitchingDocuments = 0, kSwitchingApplications = 1, kLowMemory1 = 2,
  kLowMemory2 = 3, kLowMemory3 = 4, kReleaseEverything = 5, kMaxMemoryLevel = 5
}
 
enum  MemoryState { kNormalMemoryState = 0, kConstrainedMemoryState = 1, kLowMemoryState = 2 }
 

Public Member Functions

virtual void Init ()=0
 
virtual void PurgeObjects (PurgeLevel purgeLevel)=0
 
virtual void CheckMemoryState ()=0
 
virtual bool16 MemoryPanic ()=0
 
virtual bool16 CheckMemory (bool16 showAlerts=kFalse)=0
 
virtual bool16 MemoryIsLow ()=0
 
virtual bool16 MemoryIsFailing ()=0
 
virtual void RegisterAdviseMemoryStateNotification (AdviseMemoryStateNotificationFunction func, void *refPtr)=0
 
virtual void UnregisterAdviseMemoryStateNotification (AdviseMemoryStateNotificationFunction func, void *refPtr)=0
 
virtual uint32 GetPurgeCount () const =0
 
virtual uint32 GetPurgeTime () const =0
 
virtual bool16 PurgeInProgress () const =0
 
virtual bool16 HandleAllocationFailure (size_t blockSize)=0
 
virtual void ResetFailureHandler ()=0
 
Register and de-register purge handlers
virtual void RegisterMemoryNotification (MemoryNotificationFunction func, void *refPtr)=0
 
virtual void RegisterNewMemoryNotification (NewMemoryNotificationFunction func, void *refPtr, bool16 bGrowZoneFailSafe)=0
 
virtual void UnregisterMemoryNotification (MemoryNotificationFunction func, void *refPtr)=0
 
virtual void UnregisterNewMemoryNotification (NewMemoryNotificationFunction func, void *refPtr)=0
 
- Public Member Functions inherited from IPMUnknown
virtual IPMUnknownQueryInterface (PMIID interfaceID) const =0
 
virtual void AddRef () const =0
 
virtual void Release () const =0
 

Detailed Description

The memory manager keeps track of the memory load, and acts as a central handler for memory issues.

Member Enumeration Documentation

Load on memory
Enumerator
kNormalMemoryState 

Normal state, there is plenty of memory

kConstrainedMemoryState 

Heap is relatively full, around 10-20% free (a good time to fix sizes of caches)

kLowMemoryState 

Heap is very full, less than 5% free (a good time to reduce memory footprint)

Every purge request has a priority attached to it, which is the PurgeLevel.
Enumerator
kNoPurge 

Used to indicate no purge is necessary

kSwitchingDocuments 

Called when document focus changes, releases document oriented caches

kSwitchingApplications 

Called when the application is being switched out, releases temporary memory

kLowMemory1 

Called when memory is getting tight

kLowMemory2 

Called when memory is getting more tight

kLowMemory3 

Called when memory is getting even more tight

kReleaseEverything 

Called when a memory request is about to fail. Release all caches.

kMaxMemoryLevel 

Attempt to free up memory by unloading plug-ins. Called only on the Mac, when a plug-in fails to load. Purge handlers will not get this level.

Member Function Documentation

virtual bool16 IMemoryManager::CheckMemory (bool16 showAlerts = kFalse)
pure virtual

If CheckMemory() returns kFalse the application should quit asap.

virtual void IMemoryManager::CheckMemoryState ()
pure virtual

Checks available memory and notifies registered memory state clients so thay can make caching algorithm adjustments.

virtual uint32 IMemoryManager::GetPurgeCount () const
pure virtual

Return the number of times PurgeObjects has been called

virtual uint32 IMemoryManager::GetPurgeTime () const
pure virtual

Returns the cumulative time spent in PurgeObjects

virtual bool16 IMemoryManager::HandleAllocationFailure (size_t blockSize)
pure virtual

Called when an allocation fails. It will attempt to free some memory by calling the purge handlers. Returns true if it made any progress and the caller should retry the allocation, false if no progress was made and we should give up.

Parameters
blockSize[IN] - the size of the block that the allocator failed to allocate.
virtual bool16 IMemoryManager::MemoryIsFailing ()
pure virtual

If MemoryIsFailing() returns kTrue the application should quit asap

virtual bool16 IMemoryManager::MemoryIsLow ()
pure virtual

If MemoryIsLow returns kTrue certain methods and commands will not work.

virtual bool16 IMemoryManager::MemoryPanic ()
pure virtual

Tries to free the last memory reserves. The memory manager maintains a reserve emergency block of memory that can be freed in order to satisfy memory requests when all other attempts have failed. These blocks will be reacquired as soon as the application judges the memory state has improved.

Returns
kTrue if it released any emergency block and the caller should retry, kFalse if no emergency blocks were available
virtual bool16 IMemoryManager::PurgeInProgress () const
pure virtual

Returns true if a memory purge is in progress for the calling thread. Note that the function can return false, but other threads can be purging. Reserved for internal use only.

virtual void IMemoryManager::PurgeObjects (PurgeLevel purgeLevel)
pure virtual

Tries to free some memory. Calls out to the purge handlers and requests them to free up memory. PurgeObjects is called by the new fail handler.

Parameters
purgeLevel,thepriority level of the request
virtual void IMemoryManager::RegisterAdviseMemoryStateNotification (AdviseMemoryStateNotificationFunction func,
void * refPtr 
)
pure virtual

Register a memory state notification function.

Parameters
functhe memory state notification function to register
refPtrthe pointer to pass the function when it's called
virtual void IMemoryManager::RegisterMemoryNotification (MemoryNotificationFunction func,
void * refPtr 
)
pure virtual

Register a purge handler.

Parameters
functhe memory notification function to register
refPtrthe pointer to pass the function when it's called
virtual void IMemoryManager::RegisterNewMemoryNotification (NewMemoryNotificationFunction func,
void * refPtr,
bool16 bGrowZoneFailSafe 
)
pure virtual

Register a purge handler.

Parameters
functhe memory notification function to register
refPtrthe pointer to pass the function when it's called
virtual void IMemoryManager::ResetFailureHandler ()
pure virtual

Resets the failure handler into its initial state. Called after the failure handler was invoked (one or more times) in order to reset the purge level back to normal. Reserved for internal use only.

virtual void IMemoryManager::UnregisterAdviseMemoryStateNotification (AdviseMemoryStateNotificationFunction func,
void * refPtr 
)
pure virtual

De-register a memory state notification function.

Parameters
functhe memory state notification function to de-register
refPtrthe pointer to pass the function when it's called
virtual void IMemoryManager::UnregisterMemoryNotification (MemoryNotificationFunction func,
void * refPtr 
)
pure virtual

De-register a purge handler.

Parameters
functhe memory notification function to register
refPtrthe pointer to pass the function when it's called
virtual void IMemoryManager::UnregisterNewMemoryNotification (NewMemoryNotificationFunction func,
void * refPtr 
)
pure virtual

De-register a purge handler.

Parameters
functhe memory notification function to register
refPtrthe pointer to pass the function when it's called