BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

pool.h
Go to the documentation of this file.
1 /* $Id: pool.h 4537 2013-06-19 06:47:43Z riza $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #include <pj/list.h>
22 
23 /* See if we use pool's alternate API.
24  * The alternate API is used e.g. to implement pool debugging.
25  */
26 #if PJ_HAS_POOL_ALT_API
27 # include <pj/pool_alt.h>
28 #endif
29 
30 
31 #ifndef __PJ_POOL_H__
32 #define __PJ_POOL_H__
33 
40 
294 typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
295 
300 typedef struct pj_pool_block
301 {
303  unsigned char *buf;
304  unsigned char *cur;
305  unsigned char *end;
306 } pj_pool_block;
307 
308 
313 struct pj_pool_t
314 {
319 
322 
325 
328 
331 
334 
337 
338 };
339 
340 
344 #define PJ_POOL_SIZE (sizeof(struct pj_pool_t))
345 
349 #ifndef PJ_POOL_ALIGNMENT
350 # define PJ_POOL_ALIGNMENT 4
351 #endif
352 
381  const char *name,
382  pj_size_t initial_size,
383  pj_size_t increment_size,
384  pj_pool_callback *callback);
385 
391 PJ_IDECL(void) pj_pool_release( pj_pool_t *pool );
392 
400 PJ_IDECL(const char *) pj_pool_getobjname( const pj_pool_t *pool );
401 
411 PJ_DECL(void) pj_pool_reset( pj_pool_t *pool );
412 
413 
425 
434 
447 PJ_IDECL(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size);
448 
460 PJ_IDECL(void*) pj_pool_calloc( pj_pool_t *pool, pj_size_t count,
461  pj_size_t elem);
462 
463 
475 {
476  return pj_pool_calloc(pool, 1, size);
477 }
478 
479 
491 #define PJ_POOL_ALLOC_T(pool,type) \
492  ((type*)pj_pool_alloc(pool, sizeof(type)))
493 
505 #define PJ_POOL_ZALLOC_T(pool,type) \
506  ((type*)pj_pool_zalloc(pool, sizeof(type)))
507 
508 /*
509  * Internal functions
510  */
511 PJ_IDECL(void*) pj_pool_alloc_from_block(pj_pool_block *block, pj_size_t size);
512 PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size);
513 
514 
515 
520 /* **************************************************************************/
569 /* We unfortunately don't have support for factory policy options as now,
570  so we keep this commented at the moment.
571 enum PJ_POOL_FACTORY_OPTION
572 {
573  PJ_POOL_FACTORY_SERIALIZE = 1
574 };
575 */
576 
581 {
591  void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size);
592 
600  void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size);
601 
606 
610  unsigned flags;
611 
613 
621 PJ_DECL_DATA(int) PJ_NO_MEMORY_EXCEPTION;
622 
626 PJ_DECL(int) pj_NO_MEMORY_EXCEPTION(void);
627 
638 
639 
646 
647 
652 {
657 
682  pj_pool_t* (*create_pool)( pj_pool_factory *factory,
683  const char *name,
684  pj_size_t initial_size,
685  pj_size_t increment_size,
686  pj_pool_callback *callback);
687 
694  void (*release_pool)( pj_pool_factory *factory, pj_pool_t *pool );
695 
701  void (*dump_status)( pj_pool_factory *factory, pj_bool_t detail );
702 
715  pj_bool_t (*on_block_alloc)(pj_pool_factory *factory, pj_size_t size);
716 
726  void (*on_block_free)(pj_pool_factory *factory, pj_size_t size);
727 
728 };
729 
739 PJ_DECL(pj_pool_t*) pj_pool_create_int( pj_pool_factory *factory,
740  const char *name,
741  pj_size_t initial_size,
742  pj_size_t increment_size,
743  pj_pool_callback *callback);
744 
752 PJ_DECL(void) pj_pool_init_int( pj_pool_t *pool,
753  const char *name,
754  pj_size_t increment_size,
755  pj_pool_callback *callback);
756 
761 PJ_DECL(void) pj_pool_destroy_int( pj_pool_t *pool );
762 
763 
770  pj_bool_t detail )
771 {
772  (*pf->dump_status)(pf, detail);
773 }
774 
779 /* **************************************************************************/
780 
800 #define PJ_CACHING_POOL_ARRAY_SIZE 16
801 
809 {
812 
820 
827 
834 
839 
845 
850 
855 
859  char pool_buf[256 * (sizeof(size_t) / 4)];
860 
865 };
866 
867 
868 
880 PJ_DECL(void) pj_caching_pool_init( pj_caching_pool *ch_pool,
881  const pj_pool_factory_policy *policy,
882  pj_size_t max_capacity);
883 
884 
890 PJ_DECL(void) pj_caching_pool_destroy( pj_caching_pool *ch_pool );
891 
896 # if PJ_FUNCTIONS_ARE_INLINED
897 # include "pool_i.h"
898 # endif
899 
901 
902 #endif /* __PJ_POOL_H__ */
903 

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.