free
Frees memory returned from an IMSL C Math Library function.
Synopsis
#include <imsl.h>
void imsl_free (void *data)
Required Arguments
void *data (Input)
A pointer to data returned from an IMSL C Math Library function.
Description
The function imsl_free frees memory using the C runtime library used by the IMSL C Math Library for allocation. It is a wrapper around the standard C runtime function free.
Function imsl_free can always be used to free memory allocated by the IMSL C Math Library, but is required if an application has linked to multiple copies of the C runtime library, with each copy having its own set of heap allocation structures. In this situation, using the C runtime function free can result in memory being allocated with one copy of the C runtime library and freed with a different copy, which may cause abnormal termination. Using imsl_free ensures that the same C runtime library is used for both allocation and freeing.
Note that imsl_free should be used only to free memory that was allocated by IMSL C Math Library.
Example
This example computes a set of random numbers, prints them, and then frees the array returned from the random number generation function.
 
#include <imsl.h>
#include <stdio.h>
int main()
{
int seed = 123457;
int n_random = 5;
float *r;
imsl_random_seed_set (seed);
r = imsl_f_random_normal(n_random, 0);
printf("%s: %8.4f%8.4f%8.4f%8.4f%8.4f\n",
"Standard normal random deviates",
r[0], r[1], r[2], r[3], r[4]);
 
imsl_free(r);
}
Output
 
Standard normal random deviates: 1.8279 -0.6412 0.7266 0.1747 1.0145