Memory allocation in ircfs Memory allocation is done entirely with pools. The use of malloc, realloc, free, or any other memory allocation is strictly forbidden (except of course in pool.c, the memory module). Allocating memory. ------------------ Each module will have one or more memory pools associated with it. A pool can be created with pool_new(parent) or pool_new_n(parent,size) where parent is the parent pool (NULL if none) and size is the beginning size of the pool. (See `grep 'define DEFAULT_POOL_SIZE' pool.c` for actual default size). A pool is destroyed by pool_destroy(pool), which deallocates any child pools and any memory associated with it. Memory is allocated from a pool with one of the following functions: void *palloc(pool,size) char *pstrdup(pool,str) char *pstrdupn(pool,str,size) Each of the functions corrisponds to the usual function (eg palloc=malloc, pstrdup=strdup, etc). Freeing memory -------------- Memory is not freed until the pool is destroyed. There is no pfree function. When should I create a pool? ----------------------------- Each module should have atleast one pool. And most non-infinite structures should have a pool. For example, the session module has a main pool, and each DCC fileserv session (struct session) has its own pool. What about temporary memory --------------------------- The functions tmp_alloc, tmp_strdup, and tmp_strdupn exist to provide short lifetime memory allocations. These functions are seperate from the pool functions, but work in much the same way. Memory from the tmp_* functions is NOT guarenteed to last beyound the lifetime of the function that allocated it. HOWEVER do NOT pass memory references to tmp_* based memory to functions that may hold onto these references. e.g. do not allocate memory for event_add_listener's userdata parameter using the tmp_* function, as it will be GONE by the the event module calls your function. When is temporary (tmp_*) memory freed? --------------------------------------- At the end of the "idle" time (just before select(2) is called). idle time is after all the select(2) based calling is done, and before select() is called again. In this time routinue maintaince and cleanup stuff is usually done.