GRASS Programmer's Manual  6.4.2(2012)
dalloc.c
Go to the documentation of this file.
00001 
00026 #include <stdlib.h>
00027 #include <grass/gis.h>
00028 
00029 
00041 double *G_alloc_vector(size_t n)
00042 {
00043     return (double *)G_calloc(n, sizeof(double));
00044 }
00045 
00046 
00060 double **G_alloc_matrix(int rows, int cols)
00061 {
00062     double **m;
00063     int i;
00064 
00065     m = (double **)G_calloc(rows, sizeof(double *));
00066     m[0] = (double *)G_calloc(rows * cols, sizeof(double));
00067     for (i = 1; i < rows; i++)
00068         m[i] = m[i - 1] + cols;
00069 
00070     return m;
00071 }
00072 
00073 
00085 float *G_alloc_fvector(size_t n)
00086 {
00087     return (float *)G_calloc(n, sizeof(float));
00088 }
00089 
00090 
00104 float **G_alloc_fmatrix(int rows, int cols)
00105 {
00106     float **m;
00107     int i;
00108 
00109     m = (float **)G_calloc(rows, sizeof(float *));
00110     m[0] = (float *)G_calloc(rows * cols, sizeof(float));
00111     for (i = 1; i < rows; i++)
00112         m[i] = m[i - 1] + cols;
00113 
00114     return m;
00115 }
00116 
00117 
00129 void G_free_vector(double *v)
00130 {
00131     G_free(v);
00132     v = NULL;
00133 
00134     return;
00135 }
00136 
00137 
00149 void G_free_fvector(float *v)
00150 {
00151     G_free(v);
00152     v = NULL;
00153 
00154     return;
00155 }
00156 
00157 
00169 void G_free_matrix(double **m)
00170 {
00171     G_free(m[0]);
00172     G_free(m);
00173     m = NULL;
00174 
00175     return;
00176 }
00177 
00178 
00190 void G_free_fmatrix(float **m)
00191 {
00192     G_free(m[0]);
00193     G_free(m);
00194     m = NULL;
00195 
00196     return;
00197 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines