hpdf_mmgr.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * << Haru Free PDF Library >> -- hpdf_mmgr.h
  3. *
  4. * URL: http://libharu.org
  5. *
  6. * Copyright (c) 1999-2006 Takeshi Kanno <[email protected]>
  7. * Copyright (c) 2007-2009 Antony Dovgal <[email protected]>
  8. *
  9. * Permission to use, copy, modify, distribute and sell this software
  10. * and its documentation for any purpose is hereby granted without fee,
  11. * provided that the above copyright notice appear in all copies and
  12. * that both that copyright notice and this permission notice appear
  13. * in supporting documentation.
  14. * It is provided "as is" without express or implied warranty.
  15. *
  16. */
  17. #ifndef _HPDF_MMGR_H
  18. #define _HPDF_MMGR_H
  19. #include "hpdf_types.h"
  20. #include "hpdf_error.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef struct _HPDF_MPool_Node_Rec *HPDF_MPool_Node;
  25. typedef struct _HPDF_MPool_Node_Rec {
  26. HPDF_BYTE* buf;
  27. HPDF_UINT size;
  28. HPDF_UINT used_size;
  29. HPDF_MPool_Node next_node;
  30. } HPDF_MPool_Node_Rec;
  31. typedef struct _HPDF_MMgr_Rec *HPDF_MMgr;
  32. typedef struct _HPDF_MMgr_Rec {
  33. HPDF_Error error;
  34. HPDF_Alloc_Func alloc_fn;
  35. HPDF_Free_Func free_fn;
  36. HPDF_MPool_Node mpool;
  37. HPDF_UINT buf_size;
  38. #ifdef HPDF_MEM_DEBUG
  39. HPDF_UINT alloc_cnt;
  40. HPDF_UINT free_cnt;
  41. #endif
  42. } HPDF_MMgr_Rec;
  43. /* HPDF_mpool_new
  44. *
  45. * create new HPDF_mpool object. when memory allocation goes wrong,
  46. * it returns NULL and error handling function will be called.
  47. * if buf_size is non-zero, mmgr is configured to be using memory-pool
  48. */
  49. HPDF_MMgr
  50. HPDF_MMgr_New (HPDF_Error error,
  51. HPDF_UINT buf_size,
  52. HPDF_Alloc_Func alloc_fn,
  53. HPDF_Free_Func free_fn);
  54. void
  55. HPDF_MMgr_Free (HPDF_MMgr mmgr);
  56. void*
  57. HPDF_GetMem (HPDF_MMgr mmgr,
  58. HPDF_UINT size);
  59. void
  60. HPDF_FreeMem (HPDF_MMgr mmgr,
  61. void *aptr);
  62. #ifdef __cplusplus
  63. }
  64. #endif /* __cplusplus */
  65. #endif /* _HPDF_MMGR_H */