GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
imagery/alloc.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <grass/imagery.h>
4
5void *I_malloc(size_t n)
6{
7 void *b;
8
9 b = G_malloc(n);
10
11 return b;
12}
13
14void *I_realloc(void *b, size_t n)
15{
16 b = G_realloc(b, n);
17
18 return b;
19}
20
21int I_free(void *b)
22{
23 if ((char *)b != NULL)
24 G_free(b);
25
26 return 0;
27}
28
29double **I_alloc_double2(int a, int b)
30{
31 double **x;
32 int i;
33
34 x = (double **)I_malloc((a + 1) * sizeof(double *));
35
36 for (i = 0; i < a; i++) {
37 int n;
38
39 x[i] = (double *)I_malloc(b * sizeof(double));
40
41 for (n = 0; n < b; n++)
42 x[i][n] = 0;
43 }
44 x[a] = NULL;
45
46 return x;
47}
48
49int *I_alloc_int(int a)
50{
51 int *x;
52 int i;
53
54 x = (int *)I_malloc(a * sizeof(int));
55
56 for (i = 0; i < a; i++)
57 x[i] = 0;
58
59 return x;
60}
61
62int **I_alloc_int2(int a, int b)
63{
64 int **x;
65 int i, n;
66
67 x = (int **)I_malloc((a + 1) * sizeof(int *));
68
69 for (i = 0; i < a; i++) {
70 x[i] = (int *)I_malloc(b * sizeof(int));
71
72 for (n = 0; n < b; n++)
73 x[i][n] = 0;
74 }
75 x[a] = NULL;
76
77 return x;
78}
79
80int I_free_int2(int **x)
81{
82 int i;
83
84 if (x != NULL) {
85 for (i = 0; x[i] != NULL; i++)
86 G_free(x[i]);
87 G_free(x);
88 }
89
90 return 0;
91}
92
93int I_free_double2(double **x)
94{
95 int i;
96
97 if (x != NULL) {
98 for (i = 0; x[i] != NULL; i++)
99 G_free(x[i]);
100 G_free(x);
101 }
102
103 return 0;
104}
105
106double ***I_alloc_double3(int a, int b, int c)
107{
108 double ***x;
109 int i, n;
110
111 x = (double ***)G_malloc((a + 1) * sizeof(double **));
112
113 for (i = 0; i < a; i++) {
114 x[i] = I_alloc_double2(b, c);
115 if (x[i] == NULL) {
116 for (n = 0; n < i; n++)
117 G_free(x[n]);
118 G_free(x);
119
120 return (double ***)NULL;
121 }
122 }
123 x[a] = NULL;
124
125 return x;
126}
127
128int I_free_double3(double ***x)
129{
130 int i;
131
132 if (x != NULL) {
133 for (i = 0; x[i] != NULL; i++)
134 I_free_double2(x[i]);
135 G_free(x);
136 }
137
138 return 0;
139}
#define NULL
Definition ccmath.h:32
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:147
#define G_realloc(p, n)
Definition defs/gis.h:141
#define G_malloc(n)
Definition defs/gis.h:139
double ** I_alloc_double2(int a, int b)
double *** I_alloc_double3(int a, int b, int c)
int I_free(void *b)
void * I_malloc(size_t n)
int I_free_double3(double ***x)
int ** I_alloc_int2(int a, int b)
int I_free_double2(double **x)
int I_free_int2(int **x)
int * I_alloc_int(int a)
void * I_realloc(void *b, size_t n)
double b
Definition r_raster.c:39
#define x