Manage shared memory

The following C functions can make allocations from the database server shared memory:
The DataBlade API provides the memory-management functions in following table for the dynamic allocation of database server shared memory.
Table 1. Memory-management functions of the DataBlade API
Type of shared memory Description DataBlade API functions
User memory Memory that is accessible by its address only. User memory can be allocated in the current memory duration or have a specified memory duration. mi_alloc(), mi_dalloc(), mi_realloc(), mi_zalloc(), mi_switch_mem_duration(), mi_free()
Named memory Memory that has a name assigned and is accessible by its address or its name. Named memory has a specified memory duration. mi_named_alloc(), mi_named_zalloc(), mi_named_get(), mi_named_free()

mi_lock_memory(), mi_try_lock_memory(), mi_unlock_memory()

Important: Named memory is an advanced feature that can adversely affect your UDR if you use it incorrectly. Use it only when no regular DataBlade API feature can perform the task you need done.
Tip: A client LIBMI application can also use DataBlade API memory-management functions to perform dynamic allocations. However, these memory-management functions allocate memory from the client process, not from the shared memory of the database server. Therefore, memory that these functions allocate from within a client LIBMI application does not have a memory duration associated with it. For more information, see Manage memory in client LIBMI applications.
These DataBlade API memory-management functions in Memory-management functions of the DataBlade API work correctly with the transaction management and memory reclamation of the database server. In particular, they provide the following advantages:
  • These functions allocate the memory from shared memory so that all VPs can access it.
  • The database server automatically reclaims memory allocated with these functions.

    These functions establish a memory duration for the memory they allocate. When this memory duration expires, the database server automatically marks the memory for reclamation. For more information, see Choose the memory duration.