The memory management functions used by SOM are a subset of those supplied in the ANSI C standard library. They have the same calling interface and the same return types as their ANSI C equivalents, but include supplemental error checking. Errors detected by these functions are passed to SOMError (described in the previous section). The correspondence between SOM memory management functions and their ANSI C standard library equivalents is shown below:
┌───────────────────────────────────┬───────────────────────────────────┐ │SOM FUNCTION │EQUIVALENT ANSI C LIBRARY ROUTINE │ ├───────────────────────────────────┼───────────────────────────────────┤ │SOMMalloc │malloc │ ├───────────────────────────────────┼───────────────────────────────────┤ │SOMCalloc │calloc │ ├───────────────────────────────────┼───────────────────────────────────┤ │SOMRealloc │realloc │ ├───────────────────────────────────┼───────────────────────────────────┤ │SOMFree │free │ └───────────────────────────────────┴───────────────────────────────────┘
SOMMalloc, SOMCalloc, SOMRealloc, and SOMFree are actually global variables that point to the SOM memory management functions (rather than being the names of the functions themselves), so that users can replace them with their own memory management functions if desired. (See chapter 5 for a discussion of replacing the SOM memory management functions.)
Clearing memory for objects
The memory associated with objects initialized by a client program must also be freed by the client. The SOM-provided method somFree is used to release the storage containing the receiver object:
#include "origcls.h" main () { OrigCls myObject; myObject = OrigClsNew (); /* Code to use myObject */ _somFree (myObject); {
Clearing memory for the Environment
Any memory associated with an exception in an Environment structure is typically freed using the somExceptionFree function. (Or, the CORBA "exception_free" API can be used.) The somExceptionFree function takes the following form (also see "Example" in the previous topic for an application example):
void somExceptionFree(Environment *ev);
Note: For information on managing the memory, objects, and exceptions used by DSOM applications, see "Memory management" in Chapter 6, "Distributed SOM (DSOM)."