forked from kettner/hydrotrend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhydrofree_mem.c
86 lines (50 loc) · 1.63 KB
/
hydrofree_mem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*-------------------------------------------------------------------------------------------
* hydrofree_mem.c
*
* Author: Albert Kettner, March 2006
*
* Free allocated memory for 1D, 2D, 3D matrices for any variable: int, fload, double,
* struct, etc!
*
* Variable Def.Location Type Units Usage
* -------- ------------ ---- ----- -----
*
*-------------------------------------------------------------------------------------------*/
#include "hydrofree_mem.h"
#include <stdlib.h>
/*------------------------------------------------------
* for freeing memory (1D "matrices")
* format is: matrix name
*------------------------------------------------------*/
void
freematrix1D (void *matrixname)
{
free (matrixname);
}
/*------------------------------------------------------
* for freeing memory (2D matrices)
* format is: matrix name, number of rows
*------------------------------------------------------*/
void
freematrix2D (void **matrixname, int num_of_rows)
{
int i;
for (i = 0; i < num_of_rows; ++i)
free (matrixname[i]);
free (matrixname);
}
/*------------------------------------------------------
* for freeing memory (3D matrices)
* format is: matrix name, number of rows, number of columns
*------------------------------------------------------*/
void
freematrix3D (void ***matrixname, int num_of_rows, int num_of_columns)
{
int i, j;
for (i = 0; i < num_of_rows; ++i)
for (j = 0; j < num_of_columns; ++j)
free (matrixname[i][j]);
for (i = 0; i < num_of_rows; ++i)
free (matrixname[i]);
free (matrixname);
}