Argument passing
When an application calls, or is called by, a DMI library,
pointers to pointers to DMI data structures are frequently
passed between them. This leads to the question of which entity is
responsible for allocating, and which entity is responsible for freeing these
structures. The following rules apply:
-
Simple arguments on the stack are, as usual, the responsibility of the caller.
-
If a function returns successfully then the callee will have allocated
data structures for its output parameters, and the caller must free them.
-
If a function returns failure then the callee will not have allocated
space for the output parameters so the caller must not attempt to free them.
For examples of how this works in practice see the sample code.
WARNING:
If an application changes the memory descriptors (system or default),
there is a risk that memory will be allocated with one memory model
and freed with another. In a multi-threaded program it is almost impossible
to guarantee that this will not happen. Therefore the use of
non NULL memory descriptors is strongly discouraged.
Next topic:
Helper functions
Previous topic:
Default memory management model
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004