GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gis/alloc.c
Go to the documentation of this file.
1 
14 #include <stdlib.h>
15 #include <grass/gis.h>
16 #include <grass/glocale.h>
17 
30 void *G__malloc(const char *file, int line, size_t n)
31 {
32  void *buf;
33 
34  if (n <= 0)
35  n = 1; /* make sure we get a valid request */
36 
37  buf = malloc(n);
38  if (!buf) {
39  struct Cell_head window;
40 
41  G_get_window(&window);
42  G_important_message(_("Current region rows: %d, cols: %d"),
43  window.rows, window.cols);
44 
45  G_fatal_error(_("G_malloc: unable to allocate %lu bytes of memory at %s:%d"),
46  (unsigned long) n, file, line);
47  }
48 
49  return buf;
50 }
51 
68 void *G__calloc(const char *file, int line, size_t m, size_t n)
69 {
70  void *buf;
71 
72  if (m <= 0)
73  m = 1; /* make sure we get a valid requests */
74  if (n <= 0)
75  n = 1;
76 
77  buf = calloc(m, n);
78  if (!buf) {
79  struct Cell_head window;
80 
81  G_get_window(&window);
82  G_important_message(_("Current region rows: %d, cols: %d"),
83  window.rows, window.cols);
84 
85  G_fatal_error(_("G_calloc: unable to allocate %lu * %lu bytes of memory at %s:%d"),
86  (unsigned long) m, (unsigned long) n, file, line);
87  }
88 
89  return buf;
90 }
91 
92 
111 void *G__realloc(const char *file, int line, void *buf, size_t n)
112 {
113  if (n <= 0)
114  n = 1; /* make sure we get a valid request */
115 
116  if (!buf)
117  buf = malloc(n);
118  else
119  buf = realloc(buf, n);
120 
121  if (!buf) {
122  struct Cell_head window;
123 
124  G_get_window(&window);
125  G_important_message(_("Current region rows: %d, cols: %d"),
126  window.rows, window.cols);
127 
128  G_fatal_error(_("G_realloc: unable to allocate %lu bytes of memory at %s:%d"),
129  (unsigned long) n, file, line);
130  }
131 
132  return buf;
133 }
134 
135 
142 void G_free(void *buf)
143 {
144  free(buf);
145 }
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
void G_important_message(const char *msg,...)
Print a message to stderr even in brief mode (verbosity=1)
void * G__realloc(const char *file, int line, void *buf, size_t n)
Memory reallocation.
Definition: gis/alloc.c:111
void * G__malloc(const char *file, int line, size_t n)
Memory allocation.
Definition: gis/alloc.c:30
void * malloc(YYSIZE_T)
int G_get_window(struct Cell_head *window)
read the database region
Definition: get_window.c:47
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
void * G__calloc(const char *file, int line, size_t m, size_t n)
Memory allocation.
Definition: gis/alloc.c:68
void free(void *)
#define file
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int n
Definition: dataquad.c:291