GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
linkm/init.c
Go to the documentation of this file.
1/*
2 ** Written by David Gerdes US Army Construction Engineering Research Lab
3 ** April 1992
4 ** Copyright 1992 USA-CERL All rights reserved.
5 **
6 ****************************************************************************
7 *
8 * MODULE: LINKED LIST MEMORY MANAGER
9 *
10 * AUTHOR(S): David Gerdes 1992, US Army Construction Engineering Research
11 * Lab
12 *
13 * PURPOSE: Outputs a raster map layer showing the cumulative cost
14 * of moving between different geographic locations on an
15 * input raster map layer whose cell category values
16 * represent cost.
17 *
18 * SPDX-FileCopyrightText: 1999, 2006 GRASS Development Team
19 * SPDX-License-Identifier: GPL-2.0-or-later
20 *
21 ***************************************************************************/
22
23#include <stdlib.h>
24#include <grass/linkm.h>
25
26static int link_chunk_size = 100;
27static int link_exit_flag = 0;
28
29void link_set_chunk_size(int size)
30{
31 link_chunk_size = size;
32}
33
35{
36 link_exit_flag = flag;
37}
38
39struct link_head *link_init(int size)
40{
41
42 struct link_head *Head;
43
44 if (NULL == (Head = (struct link_head *)malloc(sizeof(struct link_head))))
45 return NULL;
46
47 if (NULL ==
48 (Head->ptr_array = (VOID_T **)malloc(sizeof(VOID_T *) * PTR_CNT))) {
49 free(Head);
50 return NULL;
51 }
52
53 Head->max_ptr = 0;
54 Head->Unused = NULL;
55 Head->alloced = PTR_CNT;
56 Head->unit_size =
57 size < (int)sizeof(VOID_T *) ? (int)sizeof(VOID_T *) : size;
58 Head->chunk_size = link_chunk_size;
59 Head->exit_flag = link_exit_flag;
60
61 return Head;
62}
63
65{
66 register int i;
67
68 if (Head == NULL)
69 return;
70
71 if (Head->ptr_array) {
72 for (i = 0; i < Head->max_ptr; i++)
73 if (Head->ptr_array[i] != NULL)
74 free(Head->ptr_array[i]);
75 free(Head->ptr_array);
76 free(Head);
77 }
78}
#define NULL
Definition ccmath.h:32
void link_exit_on_error(int flag)
Definition linkm/init.c:34
void link_cleanup(struct link_head *Head)
Definition linkm/init.c:64
void link_set_chunk_size(int size)
Definition linkm/init.c:29
struct link_head * link_init(int size)
Definition linkm/init.c:39
#define VOID_T
Definition linkm.h:8
#define PTR_CNT
Definition linkm.h:10
void * malloc(unsigned)
void free(void *)