GRASS Programmer's Manual
6.4.2(2012)
|
00001 /* 00002 ** Written by David Gerdes US Army Construction Engineering Research Lab 00003 ** April 1992 00004 ** Copyright 1992 USA-CERL All rights reserved. 00005 ** 00006 **************************************************************************** 00007 * 00008 * MODULE: LINKED LIST MEMORY MANAGER 00009 * 00010 * AUTHOR(S): David Gerdes 1992, US Army Construction Engineering Research Lab 00011 * 00012 * PURPOSE: Outputs a raster map layer showing the cumulative cost 00013 * of moving between different geographic locations on an 00014 * input raster map layer whose cell category values 00015 * represent cost. 00016 * 00017 * COPYRIGHT: (C) 1999, 2006 by the GRASS Development Team 00018 * 00019 * This program is free software under the GNU General Public 00020 * License (>=v2). Read the file COPYING that comes with GRASS 00021 * for details. 00022 * 00023 ***************************************************************************/ 00024 #include <stdlib.h> 00025 #include <grass/linkm.h> 00026 00027 static int link_chunk_size = 100; 00028 static int link_exit_flag = 0; 00029 00030 void link_set_chunk_size(int size) 00031 { 00032 link_chunk_size = size; 00033 } 00034 00035 void link_exit_on_error(int flag) 00036 { 00037 link_exit_flag = flag; 00038 } 00039 00040 struct link_head *link_init(int size) 00041 { 00042 00043 struct link_head *Head; 00044 00045 if (NULL == (Head = (struct link_head *)malloc(sizeof(struct link_head)))) 00046 return NULL; 00047 00048 if (NULL == 00049 (Head->ptr_array = (VOID_T **) malloc(sizeof(VOID_T *) * PTR_CNT))) { 00050 free(Head); 00051 return NULL; 00052 } 00053 00054 Head->max_ptr = 0; 00055 Head->Unused = NULL; 00056 Head->alloced = PTR_CNT; 00057 Head->unit_size = size < sizeof(VOID_T *) ? sizeof(VOID_T *) : size; 00058 Head->chunk_size = link_chunk_size; 00059 Head->exit_flag = link_exit_flag; 00060 00061 return Head; 00062 } 00063 00064 void link_cleanup(struct link_head *Head) 00065 { 00066 register int i; 00067 00068 if (Head == NULL) 00069 return; 00070 00071 if (Head->ptr_array) { 00072 for (i = 0; i < Head->max_ptr; i++) 00073 if (Head->ptr_array[i] != NULL) 00074 free(Head->ptr_array[i]); 00075 free(Head->ptr_array); 00076 free(Head); 00077 } 00078 }