A high-performance general-purpose compute library

Interfaces for writing custom memory managers. More...

Modules

 Memory Manager API
 Functions for defining custom memory managers.
 
 Memory Manager Utils
 Set and unset memory managers, set and get manager payloads, function setters.
 
 Native Memory Interface
 Native alloc, native free, get device id, etc.
 

Detailed Description

Interfaces for writing custom memory managers.

Create and set a custom memory manager by first defining the relevant closures for each required function, for example:

af_err my_initialize(af_memory_manager manager) {
void* myPayload = malloc(sizeof(MyPayload_t));
af_memory_manager_set_payload(manager, myPayload);
// ...
}
af_err my_allocated(af_memory_manager handle, size_t* size, void* ptr) {
void* myPayload;
af_memory_manager_get_payload(manager, &myPayload);
// ...
}
af_err
Definition: defines.h:71
void * af_memory_manager
Definition: memory.h:22
AFAPI af_err af_memory_manager_get_payload(af_memory_manager handle, void **payload)
Gets the payload ptr from an af_memory_manager.
AFAPI af_err af_memory_manager_set_payload(af_memory_manager handle, void *payload)
Sets the payload ptr from an af_memory_manager.

Create an af_memory_manager and attach relevant closures:

af_memory_manager_set_initialize_fn(manager, my_initialize);
af_memory_manager_set_allocated_fn(manager, my_allocated);
// ...
AFAPI af_err af_memory_manager_set_initialize_fn(af_memory_manager handle, af_memory_manager_initialize_fn fn)
Sets an af_memory_manager_initialize_fn for a memory manager.
AFAPI af_err af_create_memory_manager(af_memory_manager *out)
Creates an af_memory_manager handle.
AFAPI af_err af_memory_manager_set_allocated_fn(af_memory_manager handle, af_memory_manager_allocated_fn fn)
Sets an af_memory_manager_allocated_fn for a memory manager.

Set the memory manager to be active, which shuts down the existing memory manager:

AFAPI af_err af_set_memory_manager(af_memory_manager handle)
Sets an af_memory_manager to be the default memory manager for non-pinned memory allocations in Array...

Unset to re-create and reset an instance of the default memory manager:

AFAPI af_err af_unset_memory_manager()
Reset the memory manager being used in ArrayFire to the default memory manager, shutting down the exi...