GRASS GIS 7 Programmer's Manual  7.9.dev(2020)-164b658f1
gis/alloc.c File Reference

GIS Library - Memory allocation routines. More...

#include <stdlib.h>
#include <grass/gis.h>
#include <grass/glocale.h>
Include dependency graph for gis/alloc.c:

Go to the source code of this file.

Functions

void * G__malloc (const char *file, int line, size_t n)
 Memory allocation. More...
 
void * G__calloc (const char *file, int line, size_t m, size_t n)
 Memory allocation. More...
 
void * G__realloc (const char *file, int line, void *buf, size_t n)
 Memory reallocation. More...
 
void G_free (void *buf)
 Free allocated memory. More...
 
void * G_incr_void_ptr (const void *ptr, size_t size)
 Advance void pointer. More...
 

Detailed Description

GIS Library - Memory allocation routines.

(C) 1999-2009 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL

Definition in file gis/alloc.c.

Function Documentation

◆ G__calloc()

void* G__calloc ( const char *  file,
int  line,
size_t  m,
size_t  n 
)

Memory allocation.

Allocates a properly aligned block of memory n*m bytes in length, initializes the allocated memory to zero, and returns a pointer to the allocated block of memory.

Dies with error message on memory allocation fail.

Note: Allocating memory for reading and writing raster maps is discussed in Allocating Raster I/O Buffers.

Parameters
filefine name
lineline number
melement size
nnumber of elements

Definition at line 72 of file gis/alloc.c.

◆ G__malloc()

void* G__malloc ( const char *  file,
int  line,
size_t  n 
)

Memory allocation.

Allocates a block of memory at least n bytes which is aligned properly for all data types. A pointer to the aligned block is returned.

Dies with error message on memory allocation fail.

Parameters
filefile name
lineline number
nnumber of elements

Definition at line 32 of file gis/alloc.c.

◆ G__realloc()

void* G__realloc ( const char *  file,
int  line,
void *  buf,
size_t  n 
)

Memory reallocation.

Changes the size of a previously allocated block of memory at ptr and returns a pointer to the new block of memory. The size may be larger or smaller than the original size. If the original block cannot be extended "in place", then a new block is allocated and the original block copied to the new block.

Note: If buf is NULL, then this routine simply allocates a block of n bytes else buf must point to memory that has been dynamically allocated by G_malloc(), G_calloc(), G_realloc(), malloc(3), alloc(3), or realloc(3).. This routine works around broken realloc() routines, which do not handle a NULL buf.

Parameters
filefile name
lineline number
[in,out]bufbuffer holding original data
[in]narray size

Definition at line 118 of file gis/alloc.c.

◆ G_free()

void G_free ( void *  buf)

Free allocated memory.

Parameters
[in,out]bufbuffer holding original data

Definition at line 149 of file gis/alloc.c.

References free().

Referenced by cairo_write_ppm(), close_band_files(), db_CatValArray_free(), db_d_append_error(), destroy_si_struct(), dig_cidx_free(), dig_file_free(), dig_free_area(), dig_free_isle(), dig_free_line(), dig_free_node(), dig_free_plus_areas(), dig_free_plus_isles(), dig_free_plus_lines(), dig_free_plus_nodes(), free_datum_list(), free_ellps_list(), free_fontcap(), free_perimeters(), free_slice_buff(), free_vol_buff(), free_volfile_buffs(), G__read_Cell_head(), G_free_fmatrix(), G_free_fvector(), G_free_ilist(), G_free_imatrix(), G_free_ivector(), G_free_key_value(), G_free_list(), G_free_matrix(), G_free_tokens(), G_free_vector(), G_get_available_mapsets(), G_init_ilist(), G_list(), G_ls(), G_math_free_spmatrix(), G_math_free_spvector(), G_math_solver_sparse_gs(), G_math_solver_sparse_jacobi(), G_matrix_free(), G_matrix_LU_solve(), G_read_compressed(), G_vector_free(), gk_free_key(), gk_make_linear_framesfromkeys(), gp_free_site(), GPJ_free_datum(), GPJ_free_datum_transform(), GPJ_free_ellps(), GPJ_init_transform(), GPJ_osr_to_grass(), GPJ_set_csv_loc(), gs_free_surf(), gs_init_normbuff(), gs_malloc_lookup(), GS_write_ppm(), GS_write_tif(), gv_free_vect(), gv_free_vectmem(), gvl_free_vol(), GVL_isosurf_del(), gvl_isosurf_freemem(), Gvl_unload_colors_data(), I_free(), I_free_double2(), I_free_double3(), I_free_int2(), I_iclass_free_statistics(), I_sc_free_cats(), kdtree_destroy(), N_free_geom_data(), N_free_gradient_2d(), N_free_gradient_3d(), N_free_gradient_field_2d(), N_free_gradient_field_3d(), N_free_gradient_neighbours_2d(), N_free_gradient_neighbours_3d(), N_free_gradient_neighbours_x(), N_free_gradient_neighbours_y(), N_free_gradient_neighbours_z(), N_free_les(), NetA_timetable_result_release(), Nviz_destroy_render_window(), Nviz_draw_all_site(), Nviz_draw_all_vol(), Nviz_get_exag(), path_free(), pg_destroy_struct(), Rast__close_null(), Rast__color_free_fp_lookup(), Rast__color_free_lookup(), Rast__create_window_mapping(), Rast_clear_history(), Rast_close_gdal_link(), Rast_close_gdal_write_link(), Rast_close_vrt(), Rast_command_history(), Rast_format_history(), Rast_fpreclass_reset(), Rast_free_cats(), Rast_free_cell_stats(), Rast_free_histogram(), Rast_free_history(), Rast_free_reclass(), Rast_get_vrt_row(), Rast_map_to_img_str(), Rast_quant_free(), Rast_set_d_cat(), Rast_set_history(), Segment_close(), Segment_release(), set_proj_share(), tgis_free_map_list(), tgis_init_map_list(), V1_close_ogr(), V1_close_pg(), Vect__free_cache(), Vect__free_offset(), Vect_build_ogr(), Vect_build_pg(), Vect_close(), Vect_destroy_boxlist(), Vect_destroy_cat_list(), Vect_destroy_cats_struct(), Vect_destroy_line_struct(), Vect_destroy_list(), Vect_destroy_map_struct(), Vect_get_finfo_geometry_type(), Vect_new_varray(), Vect_set_comment(), Vect_set_date(), Vect_set_map_date(), Vect_set_map_name(), Vect_set_organization(), Vect_set_person(), and write_pgm().

◆ G_incr_void_ptr()

void* G_incr_void_ptr ( const void *  ptr,
size_t  size 
)

Advance void pointer.

Advances void pointer by size bytes. Returns new pointer value.

Useful in raster row processing loops, substitutes

CELL *cell;
cell += n;

Now

rast = G_incr_void_ptr(rast, Rast_cell_size(data_type))

(where rast is void* and data_type is RASTER_MAP_TYPE can be used instead of rast++.)

Very useful to generalize the row processing - loop i.e.

void * buf_ptr += Rast_cell_size(data_type)
Parameters
ptrpointer
sizebuffer size
Returns
pointer to the data

Definition at line 186 of file gis/alloc.c.

Referenced by Rast_row_update_fp_range().