GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
tilealloc.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include "raster3d_intern.h"
6 
7 /*---------------------------------------------------------------------------*/
8 
9 /*!
10  * \brief
11  *
12  * Allocates a vector of <em>nofTiles</em> tiles with the same dimensions
13  * as the tiles of <em>map</em> and large enough to store cell-values of
14  * <em>type</em>.
15  *
16  * \param map
17  * \param nofTiles
18  * \param type
19  * \return void * : a pointer to the vector ... if successful,
20  * NULL ... otherwise.
21  */
22 
23 void *Rast3d_alloc_tiles_type(RASTER3D_Map *map, int nofTiles, int type)
24 {
25  void *tiles;
26 
27  tiles = Rast3d_malloc(map->tileSize * Rast3d_length(type) * nofTiles);
28  if (tiles == NULL) {
29  Rast3d_error("Rast3d_alloc_tiles_type: error in Rast3d_malloc");
30  return NULL;
31  }
32 
33  return tiles;
34 }
35 
36 /*---------------------------------------------------------------------------*/
37 
38 /*!
39  * \brief
40  *
41  * Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles,
42  * Rast3d_file_type_map (map)).
43  *
44  * \param map
45  * \param nofTiles
46  * \return void *
47  */
48 
49 void *Rast3d_alloc_tiles(RASTER3D_Map *map, int nofTiles)
50 {
51  void *tiles;
52 
53  tiles = Rast3d_alloc_tiles_type(map, nofTiles, map->typeIntern);
54  if (tiles == NULL) {
55  Rast3d_error("Rast3d_alloc_tiles: error in Rast3d_alloc_tiles_type");
56  return NULL;
57  }
58 
59  return tiles;
60 }
61 
62 /*---------------------------------------------------------------------------*/
63 
64 /*!
65  * \brief
66  *
67  * Is equivalent to <tt>Rast3d_free (tiles);</tt>
68  *
69  * \param tiles
70  * \return void
71  */
72 
73 void Rast3d_free_tiles(void *tiles)
74 {
75  Rast3d_free(tiles);
76 }
#define NULL
Definition: ccmath.h:32
void Rast3d_free(void *)
Same as free (ptr).
int Rast3d_length(int)
Definition: raster3d/misc.c:75
void Rast3d_error(const char *,...) __attribute__((format(printf
void * Rast3d_malloc(int)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
int tileSize
Definition: raster3d.h:180
int typeIntern
Definition: raster3d.h:150
void * Rast3d_alloc_tiles(RASTER3D_Map *map, int nofTiles)
Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles, Rast3d_file_type_map (map)).
Definition: tilealloc.c:49
void * Rast3d_alloc_tiles_type(RASTER3D_Map *map, int nofTiles, int type)
Allocates a vector of nofTiles tiles with the same dimensions as the tiles of map and large enough to...
Definition: tilealloc.c:23
void Rast3d_free_tiles(void *tiles)
Is equivalent to Rast3d_free (tiles);
Definition: tilealloc.c:73