S
Simon Nickerson
I have a function which looks like this:
void rho(matrix_t *out, matrix_t *in)
{
static int firsttime = 1;
static matrix_t *words;
/* ... other variables ... */
if (firsttime) {
firsttime = 0
words = malloc(NUM_WORDS * sizeof(matrix_t));
if (!words) {
/* complain */
}
/* calculate words[0], ... words[NUM_WORDS-1] */
}
/* other processing */
}
The idea is that a number of matrices are computed the first time
the function is run, which can then be used for subsequent runs.
However, the memory never gets freed. Is this legal, and if not,
what's the best way round it?
void rho(matrix_t *out, matrix_t *in)
{
static int firsttime = 1;
static matrix_t *words;
/* ... other variables ... */
if (firsttime) {
firsttime = 0
words = malloc(NUM_WORDS * sizeof(matrix_t));
if (!words) {
/* complain */
}
/* calculate words[0], ... words[NUM_WORDS-1] */
}
/* other processing */
}
The idea is that a number of matrices are computed the first time
the function is run, which can then be used for subsequent runs.
However, the memory never gets freed. Is this legal, and if not,
what's the best way round it?