1 /*
    2  * << Haru Free PDF Library >> -- hpdf_mmgr.h
    3  *
    4  * URL: http://libharu.org
    5  *
    6  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
    7  * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
    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 
   18 #ifndef _HPDF_MMGR_H
   19 #define _HPDF_MMGR_H
   20 
   21 #include "hpdf_types.h"
   22 #include "hpdf_error.h"
   23 
   24 #ifdef __cplusplus
   25 extern "C" {
   26 #endif
   27 
   28 typedef struct  _HPDF_MPool_Node_Rec  *HPDF_MPool_Node;
   29 
   30 typedef struct  _HPDF_MPool_Node_Rec {
   31     HPDF_BYTE*       buf;
   32     HPDF_UINT        size;
   33     HPDF_UINT        used_size;
   34     HPDF_MPool_Node  next_node;
   35 } HPDF_MPool_Node_Rec;
   36 
   37 
   38 typedef struct  _HPDF_MMgr_Rec  *HPDF_MMgr;
   39 
   40 typedef struct  _HPDF_MMgr_Rec {
   41     HPDF_Error        error;
   42     HPDF_Alloc_Func   alloc_fn;
   43     HPDF_Free_Func    free_fn;
   44     HPDF_MPool_Node   mpool;
   45     HPDF_UINT         buf_size;
   46 
   47 #ifdef HPDF_MEM_DEBUG
   48     HPDF_UINT         alloc_cnt;
   49     HPDF_UINT         free_cnt;
   50 #endif
   51 } HPDF_MMgr_Rec;
   52 
   53 
   54 /*  HPDF_mpool_new
   55  *
   56  *  create new HPDF_mpool object. when memory allocation goes wrong,
   57  *  it returns NULL and error handling function will be called.
   58  *  if buf_size is non-zero, mmgr is configured to be using memory-pool
   59  */
   60 HPDF_MMgr
   61 HPDF_MMgr_New  (HPDF_Error       error,
   62                 HPDF_UINT        buf_size,
   63                 HPDF_Alloc_Func  alloc_fn,
   64                 HPDF_Free_Func   free_fn);
   65 
   66 
   67 void
   68 HPDF_MMgr_Free  (HPDF_MMgr  mmgr);
   69 
   70 
   71 void*
   72 HPDF_GetMem  (HPDF_MMgr  mmgr,
   73               HPDF_UINT  size);
   74 
   75 
   76 void
   77 HPDF_FreeMem  (HPDF_MMgr  mmgr,
   78                void       *aptr);
   79 
   80 #ifdef __cplusplus
   81 }
   82 #endif /* __cplusplus */
   83 
   84 #endif /* _HPDF_MMGR_H */
   85