File: dalloc.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (135 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download | duplicates (2)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "gis.h"
#include <stdlib.h>


/*!
 * \brief memory allocation
 *
 * Allocate a 
 * vector (array) of <b>n</b> doubles initialized to zero.
 *
 *  \param n
 *  \return double * 
 */

 double *G_alloc_vector(int n)
{
    return (double *) G_calloc (n, sizeof(double));
}


/*!
 * \brief memory allocation
 *
 * Allocate a matrix of <b>rows</b> by <b>cols</b> doubles initialized
 * to zero.
 *
 *  \param rows
 *  \param cols
 *  \return double ** 
 */

 double **G_alloc_matrix( int rows,int cols)
{
    double **m;
    int i;

    m = (double **) G_calloc (rows, sizeof(double *));
    m[0] = (double *) G_calloc (rows*cols, sizeof(double));
    for (i = 1; i < rows; i++)
	m[i] = m[i-1] + cols;
    return m;
}


/*!
 * \brief memory allocation
 *
 * Allocate a
 * vector (array) of <b>n</b> floats initialized to zero.
 *
 *  \param n
 *  \return float * 
 */

 float *G_alloc_fvector(int n)
{
    return (float *) G_calloc (n, sizeof(float));
}


/*!
 * \brief memory allocation
 *
 * Allocate a matrix of <b>rows</b> by <b>cols</b> floats initialized
 * to zero.
 *
 *  \param rows
 *  \param cols
 *  \return float ** 
 */

 float **G_alloc_fmatrix( int rows,int cols)
{
    float **m;
    int i;

    m = (float **) G_calloc (rows, sizeof(float *));
    m[0] = (float *) G_calloc (rows*cols, sizeof(float));
    for (i = 1; i < rows; i++)
	m[i] = m[i-1] + cols;
    return m;
}


/*!
 * \brief memory deallocation
 *
 * Deallocate a
 * vector (array) of doubles or floats.
 *
 *  \param v
 *  \return int
 */

 int G_free_vector(double *v)
{
    free (v);
    return 0;
}


/*!
 * \brief memory deallocation
 *
 * Deallocate 
 * a matrix of doubles.
 *
 *  \param m
 *  \return int
 */

 int G_free_matrix( double **m)
{
    free (m[0]);
    free (m);
    return 0;
}


/*!
 * \brief memory deallocation
 *
 * Deallocate
 * a matrix of floats.
 *
 *  \param m
 *  \return int
 */

 int G_free_fmatrix(float **m)
{
    free (m[0]);
    free (m);
    return 0;
}