GRASS GIS 7 Programmer's Manual
7.8.2(2019)-exported
ialloc.c
Go to the documentation of this file.
1
2
/**
3
* \file ialloc.c
4
*
5
* \brief Matrix memory management functions.
6
*
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or (at
10
* your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
*
21
* \author GRASS GIS Development Team
22
*
23
* \date 2004-2006
24
*/
25
26
27
#include <stdlib.h>
28
#include <grass/gis.h>
29
30
31
/**
32
* \fn int *G_alloc_ivector (size_t n)
33
*
34
* \brief Vector matrix memory allocation.
35
*
36
* Allocate a vector (array) of <b>n</b> integers initialized to zero.
37
*
38
* \param[in] n size of vector to allocate
39
* \return integer *
40
*/
41
int
*
G_alloc_ivector
(
size_t
n)
42
{
43
return
(
int
*)G_calloc(n,
sizeof
(
int
));
44
}
45
46
/**
47
* \fn int **G_alloc_imatrix (int rows, int cols)
48
*
49
* \brief Matrix memory allocation.
50
*
51
* Allocate a matrix of <b>rows</b> by <b>cols</b> integers initialized
52
* to zero.
53
*
54
* \param[in] rows number of rows in matrix
55
* \param[in] cols number of columns in matrix
56
* \return int **
57
*/
58
int
**
G_alloc_imatrix
(
int
rows,
int
cols)
59
{
60
int
**m;
61
int
i;
62
63
m = (
int
**)G_calloc(rows,
sizeof
(
int
*));
64
m[0] = (
int
*)G_calloc((
size_t
) rows * cols,
sizeof
(int));
65
for
(i = 1; i < rows; i++)
66
m[i] = m[i - 1] + cols;
67
68
return
m;
69
}
70
71
/**
72
* \fn void G_free_ivector(int *v)
73
*
74
* \brief Vector memory deallocation.
75
*
76
* Deallocate a vector (array) of integers.
77
*
78
* \param[in,out] v vector to free
79
* \return void
80
*/
81
void
G_free_ivector
(
int
*v)
82
{
83
G_free
(v);
84
v =
NULL
;
85
86
return
;
87
}
88
89
/**
90
* \fn int G_free_imatrix (int **m)
91
*
92
* \brief Matrix memory deallocation.
93
*
94
* Deallocate a matrix of integers.
95
*
96
* \param[in,out] m matrix to free
97
* \return void
98
*/
99
void
G_free_imatrix
(
int
**m)
100
{
101
G_free
(m[0]);
102
G_free
(m);
103
m =
NULL
;
104
105
return
;
106
}
G_alloc_ivector
int * G_alloc_ivector(size_t n)
Vector matrix memory allocation.
Definition:
ialloc.c:41
G_free
void G_free(void *buf)
Free allocated memory.
Definition:
alloc.c:149
NULL
#define NULL
Definition:
ccmath.h:32
G_free_imatrix
void G_free_imatrix(int **m)
Matrix memory deallocation.
Definition:
ialloc.c:99
G_free_ivector
void G_free_ivector(int *v)
Vector memory deallocation.
Definition:
ialloc.c:81
G_alloc_imatrix
int ** G_alloc_imatrix(int rows, int cols)
Matrix memory allocation.
Definition:
ialloc.c:58
gmath
ialloc.c
Generated on Mon Apr 25 2022 14:03:04 for GRASS GIS 7 Programmer's Manual by
1.8.17