GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-2653d7b383
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  * COPYRIGHT: (C) 1999, 2006 by the GRASS Development Team
19  *
20  * This program is free software under the GNU General Public
21  * License (>=v2). Read the file COPYING that comes with GRASS
22  * for details.
23  *
24  ***************************************************************************/
25 
26 #include <stdlib.h>
27 #include <grass/linkm.h>
28 
29 static int link_chunk_size = 100;
30 static int link_exit_flag = 0;
31 
32 void link_set_chunk_size(int size)
33 {
34  link_chunk_size = size;
35 }
36 
37 void link_exit_on_error(int flag)
38 {
39  link_exit_flag = flag;
40 }
41 
42 struct link_head *link_init(int size)
43 {
44 
45  struct link_head *Head;
46 
47  if (NULL == (Head = (struct link_head *)malloc(sizeof(struct link_head))))
48  return NULL;
49 
50  if (NULL ==
51  (Head->ptr_array = (VOID_T **)malloc(sizeof(VOID_T *) * PTR_CNT))) {
52  free(Head);
53  return NULL;
54  }
55 
56  Head->max_ptr = 0;
57  Head->Unused = NULL;
58  Head->alloced = PTR_CNT;
59  Head->unit_size =
60  size < (int)sizeof(VOID_T *) ? (int)sizeof(VOID_T *) : size;
61  Head->chunk_size = link_chunk_size;
62  Head->exit_flag = link_exit_flag;
63 
64  return Head;
65 }
66 
67 void link_cleanup(struct link_head *Head)
68 {
69  register int i;
70 
71  if (Head == NULL)
72  return;
73 
74  if (Head->ptr_array) {
75  for (i = 0; i < Head->max_ptr; i++)
76  if (Head->ptr_array[i] != NULL)
77  free(Head->ptr_array[i]);
78  free(Head->ptr_array);
79  free(Head);
80  }
81 }
#define NULL
Definition: ccmath.h:32
void link_exit_on_error(int flag)
Definition: linkm/init.c:37
void link_cleanup(struct link_head *Head)
Definition: linkm/init.c:67
struct link_head * link_init(int size)
Definition: linkm/init.c:42
void link_set_chunk_size(int size)
Definition: linkm/init.c:32
#define VOID_T
Definition: linkm.h:8
#define PTR_CNT
Definition: linkm.h:10
void * malloc(YYSIZE_T)
void free(void *)