Access shared memory
A C UDR executes in a virtual processor, which is associated with an operating-system process. While a C UDR executes on a VP (VP #1), it can access memory that is associated with that virtual processor. This memory space includes the stack, heap, and data segments of the VP.
- The C UDR must be threadsafe.
The UDR must not assume that it can always access information that is stored in the VP memory space. This guideline is part of the requirements for a well-behaved UDR. For more information, see Create a well-behaved routine.
- The C UDR must use the DataBlade
API memory-management
functions to allocate memory dynamically.
The DataBlade API memory-management functions in Table 1 allocate memory from the shared memory of the database server, not from the memory space of a virtual processor, as the following figure shows.
Figure 2. Location of dynamically allocated memory for a C UDR
The DataBlade API memory-management functions allocate memory from shared memory, which remains accessible if a thread migrates to another virtual processor. All VPs can access information in memory that these memory-management functions allocate because all VPs can access the shared memory of the database server.
- The C UDR must ensure that it can access both the memory and its
address when it needs to.
Both the memory and the memory address must have a memory duration sufficient for all UDRs that need to access the information. For more information, see Memory-duration considerations.
- The C UDR must use the DataBlade
API memory-management
functions to dynamically allocate memory that has an associated memory
duration.
The DataBlade API memory-management functions allocate memory from the memory-duration memory pools of the database server shared memory. Therefore, the database server can automatically reclaim this memory, reducing the chance of memory leaks. For more information, see Manage shared memory.