Functions that allocate and free memory

The DataBlade® API provides public functions and semipublic functions for memory allocation.

Public functions
Allocate memory that is local to one database server thread.
Semipublic functions
Allocate named, global memory that multiple threads might share.

For either unnamed or named memory, you can specify a duration that reserves the memory for access method use beyond the life of a particular purpose function.

For most purposes, UDRs, including access methods, can allocate shared memory with the public DataBlade API memory-management functions, mi_alloc(), mi_dalloc(), or mi_zalloc(). UDRs share access to memory that a public function allocates with the pointer that the allocation function returns. For an example that allocates memory and stores a pointer, see Persistent user data. The public mi_free() function frees the memory that a public function allocates.

The memory that you allocate with public functions is available only to UDRs that execute during a single-thread table operation. Access-method UDRs might execute across multiple threads to manipulate multiple fragments or span multiple queries. UDRs that execute in multiple threads can share named memory.

The semipublic DataBlade API mi_named_alloc() or mi_named_zalloc() memory-management functions allocate named memory, the mi_named_get() function retrieves named memory, and the mi_named_free() function releases the named memory. Related semipublic functions provide for locking on named memory.
Restriction: Do not call malloc() because the memory that malloc() allocates disappears after a virtual processor switch. The access method might not properly deallocate memory that malloc() provides, especially during exception handling.