GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72636
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 Lab
11  *
12  * PURPOSE: Outputs a raster map layer showing the cumulative cost
13  * of moving between different geographic locations on an
14  * input raster map layer whose cell category values
15  * represent cost.
16  *
17  * COPYRIGHT: (C) 1999, 2006 by the GRASS Development Team
18  *
19  * This program is free software under the GNU General Public
20  * License (>=v2). Read the file COPYING that comes with GRASS
21  * for details.
22  *
23  ***************************************************************************/
24 #include <stdlib.h>
25 #include <grass/linkm.h>
26 
27 static int link_chunk_size = 100;
28 static int link_exit_flag = 0;
29 
30 void link_set_chunk_size(int size)
31 {
32  link_chunk_size = size;
33 }
34 
35 void link_exit_on_error(int flag)
36 {
37  link_exit_flag = flag;
38 }
39 
40 struct link_head *link_init(int size)
41 {
42 
43  struct link_head *Head;
44 
45  if (NULL == (Head = (struct link_head *)malloc(sizeof(struct link_head))))
46  return NULL;
47 
48  if (NULL ==
49  (Head->ptr_array = (VOID_T **) malloc(sizeof(VOID_T *) * PTR_CNT))) {
50  free(Head);
51  return NULL;
52  }
53 
54  Head->max_ptr = 0;
55  Head->Unused = NULL;
56  Head->alloced = PTR_CNT;
57  Head->unit_size = size < sizeof(VOID_T *) ? sizeof(VOID_T *) : size;
58  Head->chunk_size = link_chunk_size;
59  Head->exit_flag = link_exit_flag;
60 
61  return Head;
62 }
63 
64 void link_cleanup(struct link_head *Head)
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 VOID_T
Definition: linkm.h:8
struct link_head * link_init(int size)
Definition: linkm/init.c:40
void free(void *)
#define NULL
Definition: ccmath.h:32
void link_cleanup(struct link_head *Head)
Definition: linkm/init.c:64
void * malloc(YYSIZE_T)
void link_set_chunk_size(int size)
Definition: linkm/init.c:30
void link_exit_on_error(int flag)
Definition: linkm/init.c:35
#define PTR_CNT
Definition: linkm.h:10