|
static int | count_users () |
|
template<typename T > |
static T * | allocate (size_t num) |
|
template<typename T > |
static void | deallocate (T *ptr) |
|
static void | generateMemoryInfo (MemoryInfoMap &outMemInfoMap, const void *restrict_to=nullptr) |
|
static void | dump_info (std::ostream &output, bool format_bytes, bool includeNodeInfo, const void *restrict_to) |
|
static bool | register_allocator (IAllocator *pAllocator) |
|
static bool | unregister_allocator (IAllocator *pAllocator) |
|
static size_t | get_num_registered_allocators () |
|
static IAllocator * | get_allocator (size_t index) |
|
static IAllocator * | find_allocator (const char *pAllocatorName) |
|
template<typename T > |
static T * | create_allocator (const char *pAllocatorName) |
|
static void | dump_allocatorinfoXML (std::ostream &output, bool format_bytes) |
|
static void | dump_infoXML (std::ostream &output, bool format_bytes, bool includeNodeInfo, const void *restrict_to) |
|
static void | print_bytes (std::ostream &output, long long unsigned bytes, bool metric=true) |
|
static int | format_bytes (char *buffer, long long unsigned bytes, bool metric=true) |
|
static void | initialize () |
| The actual low-level allocator we're using. More...
|
|
static size_t | max_usage () |
|
static size_t | current_usage () |
|
static size_t | total_ram () |
|
static U64 | total_ram_64 () |
|
static size_t | total_vm () |
|
static int | free_count () |
|
static int | new_handler_count () |
|
static bool | set_current_usage (size_t target, const char *message=nullptr) |
|
static bool | reduce_current_usage (const char *message=nullptr) |
|
static void | set_max_usage (size_t new_max) |
|
static void | set_hard_max_usage (size_t final_max) |
|
static void | set_free_count (int) |
|
static void | set_new_handler_count (int) |
|
static void * | allocate_remember_size (size_t size) |
|
static void * | allocate_void (size_t bytes) |
|
static void | deallocate_remember_size (void *ptr) |
|
static void | deallocate_void (void *ptr, size_t num=0) |
|
static size_t | get_allocated_size (void *ptr) |
|
static bool | clipToCacheLimit (int &width, int &height, const DD::Image::Format &format) |
|
Memory manager for cache-like objects that can be freed and recreated if necessary so that their memory can be used for other purposes. The output buffers on Iop and the 8-bit buffers used by the Nuke viewer, and other objects fall into this class.
Each such object should call register_user() in it's constructor and unregister_user() in it's destructor.
Any code that uses allocate() and deallocate() will trigger reduce_current_usage() if the total allocated by these calls goes over max_usage(). This will only work well if the majority of large objects allocated by Nuke and plugins calls these functions, so that current_usage() reflects the actual amount of memory being used. Code that uses new/delete (and malloc on Windows) will also trigger reduce_current_usage() when the std::new_handler() is called. But this only happens when you run out of memory which may be somewhat late for safe recovery.
allocate() will also be 16-byte aligned to allow use of vector operations.
void Memory::dump_info |
( |
std::ostream & |
output, |
|
|
bool |
format_bytes, |
|
|
bool |
includeNodeInfo, |
|
|
const void * |
restrict_to |
|
) |
| |
|
static |
Prints a report about all the users and the total memory usage to the stream. Also takes a format_bytes argument which, if true, returns the bytes in a human readable format.
If restrict_to is non-zero then only users whose info() command tests and matches the restrict_to() are printed, and no summary information is used. This is currently used to dump only the info about users that belong to a Node. Result may be a zero-length string if no users match.
If includeNodeInfo is true, Node pointers associated with memory objects (eg Ops/Knobs) will be dererenced for name information. This is unsafe during shutdown, where the associated Nodes may have been deleted.
void Memory::dump_infoXML |
( |
std::ostream & |
output, |
|
|
bool |
format_bytes, |
|
|
bool |
includeNodeInfo, |
|
|
const void * |
restrict_to |
|
) |
| |
|
static |
Prints an XML report about all the users and the total memory usage to the stream. Also takes a format_bytes argument which, if true, returns the bytes in a human readable format.
If restrict_to is non-zero then only users whose info() command tests and matches the restrict_to() are printed, and no summary information is used. This is currently used to dump only the info about users that belong to a Node. Result may be a zero-length string if no users match.
If includeNodeInfo is true, Node pointers associated with memory objects (eg Ops/Knobs) will be dererenced for name information. This is unsafe during shutdown, where the associated Nodes may have been deleted.
void Memory::initialize |
( |
| ) |
|
|
static |
The actual low-level allocator we're using.
Sets total_ram() by asking the system for this information, and sets max_usage() to 50% of that. This is automatically done by many Memory calls, but you should do this if you wish to change the max_usage to some value other than this default.
Also calls std::set_new_handler(). If you don't want this, call this and then call std::set_new_handler() to set the value back. By default running out of memory in new (and in malloc in Windows) will cause it to clean up memory so it will work, and will throw a bad_alloc exception if it does not work.
bool DD::Image::Memory::clipToCacheLimit |
( |
int & |
width, |
|
|
int & |
height, |
|
|
const DD::Image::Format & |
format |
|
) |
| |
|
static |
Reduce width & height to a box so that can be allocated.
Currently an absolute maximum of 1Mb on each dimension, and an absolute maximum of 64k^2 (4Gb) on the area. This has been chosen so that several dozen 1-D arrays of pointers or floats can be allocated without running out of memory.
In addition each dimension is limited to 16k or the size of the format, whichever is larger. This smaller limit has been chosen so that the entire image can probably be allocated at once. But if the user chooses a very large format this limit is ignored and it may try to allocate far more memory than will fit. Many operations in Nuke will still work with these very large operations (especially in 64-bit versions).
Returns true if it changes the width or height.
References DD::Image::Format::height(), and DD::Image::Format::width().
Referenced by DD::Image::Iop::request().