GRASS 8 Programmer's Manual  8.5.0dev(2025)-e5e60895a1
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 void *Rast3d_alloc_tiles_type(RASTER3D_Map *map, int nofTiles, int type)
23 {
24  void *tiles;
25 
26  tiles = Rast3d_malloc(map->tileSize * Rast3d_length(type) * nofTiles);
27  if (tiles == NULL) {
28  Rast3d_error("Rast3d_alloc_tiles_type: error in Rast3d_malloc");
29  return NULL;
30  }
31 
32  return tiles;
33 }
34 
35 /*---------------------------------------------------------------------------*/
36 
37 /*!
38  * \brief
39  *
40  * Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles,
41  * Rast3d_file_type_map (map)).
42  *
43  * \param map
44  * \param nofTiles
45  * \return void *
46  */
47 void *Rast3d_alloc_tiles(RASTER3D_Map *map, int nofTiles)
48 {
49  void *tiles;
50 
51  tiles = Rast3d_alloc_tiles_type(map, nofTiles, map->typeIntern);
52  if (tiles == NULL) {
53  Rast3d_error("Rast3d_alloc_tiles: error in Rast3d_alloc_tiles_type");
54  return NULL;
55  }
56 
57  return tiles;
58 }
59 
60 /*---------------------------------------------------------------------------*/
61 
62 /*!
63  * \brief
64  *
65  * Is equivalent to <tt>Rast3d_free (tiles);</tt>
66  *
67  * \param tiles
68  * \return void
69  */
70 void Rast3d_free_tiles(void *tiles)
71 {
72  Rast3d_free(tiles);
73 }
#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:47
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:22
void Rast3d_free_tiles(void *tiles)
Is equivalent to Rast3d_free (tiles);
Definition: tilealloc.c:70