init.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. static int link_chunk_size = 100;
  27. static int link_exit_flag = 0;
  28. void link_set_chunk_size(int size)
  29. {
  30. link_chunk_size = size;
  31. }
  32. void link_exit_on_error(int flag)
  33. {
  34. link_exit_flag = flag;
  35. }
  36. struct link_head *link_init(int size)
  37. {
  38. struct link_head *Head;
  39. if (NULL == (Head = (struct link_head *)malloc(sizeof(struct link_head))))
  40. return NULL;
  41. if (NULL ==
  42. (Head->ptr_array = (VOID_T **) malloc(sizeof(VOID_T *) * PTR_CNT))) {
  43. free(Head);
  44. return NULL;
  45. }
  46. Head->max_ptr = 0;
  47. Head->Unused = NULL;
  48. Head->alloced = PTR_CNT;
  49. Head->unit_size = size < sizeof(VOID_T *) ? sizeof(VOID_T *) : size;
  50. Head->chunk_size = link_chunk_size;
  51. Head->exit_flag = link_exit_flag;
  52. return Head;
  53. }
  54. void link_cleanup(struct link_head *Head)
  55. {
  56. register int i;
  57. if (Head == NULL)
  58. return;
  59. if (Head->ptr_array) {
  60. for (i = 0; i < Head->max_ptr; i++)
  61. if (Head->ptr_array[i] != NULL)
  62. free(Head->ptr_array[i]);
  63. free(Head->ptr_array);
  64. free(Head);
  65. }
  66. }