GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
dalloc.c
Go to the documentation of this file.
1 
26 #include <stdlib.h>
27 #include <grass/gis.h>
28 
29 
41 double *G_alloc_vector(size_t n)
42 {
43  return (double *)G_calloc(n, sizeof(double));
44 }
45 
46 
60 double **G_alloc_matrix(int rows, int cols)
61 {
62  double **m;
63  int i;
64 
65  m = (double **)G_calloc(rows, sizeof(double *));
66  m[0] = (double *)G_calloc(rows * cols, sizeof(double));
67  for (i = 1; i < rows; i++)
68  m[i] = m[i - 1] + cols;
69 
70  return m;
71 }
72 
73 
85 float *G_alloc_fvector(size_t n)
86 {
87  return (float *)G_calloc(n, sizeof(float));
88 }
89 
90 
104 float **G_alloc_fmatrix(int rows, int cols)
105 {
106  float **m;
107  int i;
108 
109  m = (float **)G_calloc(rows, sizeof(float *));
110  m[0] = (float *)G_calloc(rows * cols, sizeof(float));
111  for (i = 1; i < rows; i++)
112  m[i] = m[i - 1] + cols;
113 
114  return m;
115 }
116 
117 
129 void G_free_vector(double *v)
130 {
131  G_free(v);
132  v = NULL;
133 
134  return;
135 }
136 
137 
149 void G_free_fvector(float *v)
150 {
151  G_free(v);
152  v = NULL;
153 
154  return;
155 }
156 
157 
169 void G_free_matrix(double **m)
170 {
171  G_free(m[0]);
172  G_free(m);
173  m = NULL;
174 
175  return;
176 }
177 
178 
190 void G_free_fmatrix(float **m)
191 {
192  G_free(m[0]);
193  G_free(m);
194  m = NULL;
195 
196  return;
197 }
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
double ** G_alloc_matrix(int rows, int cols)
Matrix memory allocation.
Definition: dalloc.c:60
float * G_alloc_fvector(size_t n)
Floating point vector memory allocation.
Definition: dalloc.c:85
void G_free_fmatrix(float **m)
Floating point matrix memory deallocation.
Definition: dalloc.c:190
void G_free_vector(double *v)
Vector memory deallocation.
Definition: dalloc.c:129
void G_free_matrix(double **m)
Matrix memory deallocation.
Definition: dalloc.c:169
float ** G_alloc_fmatrix(int rows, int cols)
Floating point matrix memory allocation.
Definition: dalloc.c:104
void G_free_fvector(float *v)
Vector memory deallocation.
Definition: dalloc.c:149
return NULL
Definition: dbfopen.c:1394
tuple cols
double * G_alloc_vector(size_t n)
Vector matrix memory allocation.
Definition: dalloc.c:41
int n
Definition: dataquad.c:291