|
jabberd14
1.6.2
|
Handling of memory pools. More...
#include <jabberdlib.h>Defines | |
| #define | MAX_MALLOC_TRIES 10 |
| #define | _pool__malloc malloc |
| #define | _pool__free free |
Functions | |
| void * | _retried__malloc (size_t size) |
| pool | _pool_new (char *zone, int line) |
| void | _pool_heap_free (void *arg) |
| void | _pool_cleanup_append (pool p, struct pfree *pf) |
| struct pfree * | _pool_free (pool p, pool_cleaner f, void *arg) |
| struct pheap * | _pool_heap (pool p, int size) |
| pool | _pool_new_heap (int size, char *zone, int line) |
| void * | pmalloc (pool p, int size) |
| void * | pmalloc_x (pool p, int size, char c) |
| void * | pmalloco (pool p, int size) |
| char * | pstrdup (pool p, const char *src) |
| char * | pstrdupx (pool p, const char *src) |
| int | pool_size (pool p) |
| void | pool_free (pool p) |
| void | pool_cleanup (pool p, pool_cleaner f, void *arg) |
| void | pool_stat (int full) |
Handling of memory pools.
Jabberd handles its memory allocations in pools. You create a pool, can allocate memory from it and all allocations will be freed if you free the pool. Therefore you don't have to care that each malloc is freed, you only have to take care that the pool is freed.
The normal call-flow for pools is:
pool p = pool_new(); struct mystruct *allocation1 = pmalloc(sizeof(struct mystruct)); struct myotherstruct *allocation2 = pmalloc(sizeof(struct myotherstruct)); ... pool_free(p);
| #define _pool__free free |
_pool__free updates pool__total counter if POOL_DEBUG is defined
Referenced by _pool_heap_free(), pmalloc(), and pool_free().
| #define _pool__malloc malloc |
_pool__malloc updates pool__total counter if POOL_DEBUG is defined
Referenced by _retried__malloc().
| #define MAX_MALLOC_TRIES 10 |
how many seconds we try to allocate memory
Referenced by _retried__malloc().
| void _pool_cleanup_append | ( | pool | p, |
| struct pfree * | pf | ||
| ) |
append a pool_cleaner function (callback) to a pool
mem should always be freed last
All appended pool_cleaner functions will be called if a pool is freed. This might be used to clean logically subpools.
| p | to which pool the pool_cleaner should be added |
| pf | structure containing the reference to the pool_cleaner and links for the list |
Referenced by _pool_heap(), and pmalloc().
| struct pfree* _pool_free | ( | pool | p, |
| pool_cleaner | f, | ||
| void * | arg | ||
| ) | [read] |
create a cleanup tracker
this function is used to create a pfree structure that can be passed to _pool_cleanup_append()
| p | the pool to which the pool_cleaner should be added |
| f | the function that should be called if the pool is freed |
| arg | the parameter that should be passed to the pool_cleaner function |
References _retried__malloc().
Referenced by _pool_heap(), pmalloc(), and pool_cleanup().
| struct pheap* _pool_heap | ( | pool | p, |
| int | size | ||
| ) | [read] |
create a heap and make sure it get's cleaned up
pheaps are used by memory pools internally to handle the memory allocations
| p | for which pool the heap should be created |
| size | how big the pool should be |
References _pool_cleanup_append(), _pool_free(), _pool_heap_free(), and _retried__malloc().
Referenced by _pool_new_heap(), and pmalloc().
| void _pool_heap_free | ( | void * | arg | ) |
free a memory heap (struct pheap)
| arg | which heep should be freed |
References _pool__free.
Referenced by _pool_heap().
| pool _pool_new | ( | char * | zone, |
| int | line | ||
| ) |
make an empty pool
Use the macro pool_new() instead of a direct call to this function. The macro will create the parameters for you.
| zone | the file in which the pool_new macro is called |
| line | the line in the file in which the pool_new macro is called |
References _retried__malloc(), xhash_new(), and xhash_put().
Referenced by _pool_new_heap().
| pool _pool_new_heap | ( | int | size, |
| char * | zone, | ||
| int | line | ||
| ) |
create a new memory pool and set the initial heap size
| size | the initial size of the memory pool |
| zone | the file where this function is called (for debugging) |
| line | the line in the file where this function is called |
References _pool_heap(), and _pool_new().
| void* _retried__malloc | ( | size_t | size | ) | [inline] |
try to allocate memory
If allocation fails, it will be retries for MAX_MALLOC_TRIES seconds. If it still fails, we exit the process
| size | how many bytes of memory we allocate |
References _pool__malloc, and MAX_MALLOC_TRIES.
Referenced by _pool_free(), _pool_heap(), _pool_new(), and pmalloc().
| void* pmalloc | ( | pool | p, |
| int | size | ||
| ) |
allocate memory from a memory pool
| p | the pool to use |
| size | how much memory to allocate |
References _pool__free, _pool_cleanup_append(), _pool_free(), _pool_heap(), and _retried__malloc().
Referenced by jlimit_new(), jpacket_new(), pmalloc_x(), pmalloco(), pstrdup(), strescape(), strunescape(), and xmlnode_insert_cdata().
| void* pmalloc_x | ( | pool | p, |
| int | size, | ||
| char | c | ||
| ) |
allocate memory and initialize the memory with the given char c
| p | which pool to use |
| size | the size of the allocation |
| c | the initialization character |
References pmalloc().
| void* pmalloco | ( | pool | p, |
| int | size | ||
| ) |
allocate memory and initialize the memory with zero bytes
easy safety utility (for creating blank mem for structs, etc)
| p | which pool to use |
| size | the size of the allocation |
References pmalloc().
Referenced by _new_beat(), deliver(), dialback(), dialback_in_read_db(), dialback_merlin(), dialback_miod_hash(), dialback_miod_new(), dialback_out_connection(), dialback_out_packet(), dialback_out_read(), dialback_out_read_db(), dnsrv(), dnsrv_lookup(), dpacket_new(), js_mapi_register(), js_mapi_session(), js_psend(), js_sc_session_new(), js_session_new(), js_user(), jsm(), karma_new(), mio_connect(), mio_handlers_new(), mio_init(), mio_new(), mio_write(), mod_announce(), mod_last(), mod_offline(), mod_presence(), mod_stat(), mod_version(), mtq_new(), mtq_send(), pthsock_client(), register_config(), register_phandler(), register_routing_update_callback(), register_shutdown(), srv_lookup(), srv_port2str(), xdb_cache(), xdb_file(), xdb_file_load(), xmlnode_insert_tag(), xmlnode_new_tag_pool(), xmlnode_wrap(), and xstream_new().
| void pool_cleanup | ( | pool | p, |
| pool_cleaner | f, | ||
| void * | arg | ||
| ) |
public cleanup utils, insert in a way that they are run FIFO, before mem frees
References _pool_free().
Referenced by _mio_xstream_init(), dialback(), dialback_miod_hash(), dialback_out_connection(), dnsrv(), jid_new(), js_sc_session_new(), js_session_new(), js_user(), mio_ssl_starttls(), mtq_new(), pthsock_client(), xdb_file(), xdb_sql(), xmlnode_new_tag_pool(), xmlnode_new_tag_pool_ns(), and xstream_new().
| void pool_free | ( | pool | p | ) |
free a pool (and all memory that is allocated in it)
| p | which pool to free |
References _pool__free, and xhash_zap().
Referenced by _js_session_end(), _js_users_del(), _mio_write_dump(), acl_check_access(), deliver(), deliver_config_filter(), deliver_fail(), dialback_out_connection_cleanup(), dnsrv_child_main(), heartbeat(), heartbeat_death(), instance_shutdown(), jlimit_free(), js_config(), js_sc_session_new(), main(), mio_cleanup(), mio_handlers_free(), mio_stop(), mio_write(), shutdown_callbacks(), xdb_convert_spool(), xdb_file_phandler(), xmlnode_file(), xmlnode_free(), and xmlnode_str().
| int pool_size | ( | pool | p | ) |
| void pool_stat | ( | int | full | ) |
dummy implementation: print memory pool statistics (for debugging purposes, real implementation if POOL_DEBUG is defined)
| full | make a full report? (0 = no, 1 = yes) |
Referenced by main().
| char* pstrdup | ( | pool | p, |
| const char * | src | ||
| ) |
duplicate a string and allocate memory for it
| p | the pool to use |
| src | the string that should be duplicated |
References pmalloc().
Referenced by _dialback_out_beat_packets(), deliver_config_filter(), dialback(), dialback_in_read_db(), dialback_ip_get(), dialback_out_connection(), dialback_out_connection_cleanup(), dialback_out_read(), dnsrv(), dnsrv_deliver(), dpacket_new(), jpacket_reset(), js_packet(), js_sc_session_new(), js_session_new(), jsm(), main(), mio_connect(), mio_init(), mio_listen(), mod_version(), pstrdupx(), register_config(), register_instance(), srv_inet_ntoa(), srv_lookup(), srv_xhash_join(), unregister_instance(), xdb_file(), xdb_file_full(), xdb_file_load(), xdb_sql(), xhash_from_xml(), xmlnode_change_namespace(), xmlnode_get_name(), xmlnode_put_attrib(), xmlnode_put_attrib_ns(), xmlnode_serialize_string(), xstream_header_char(), and xstream_parse_error().
1.7.6.1