Previously, the isc_mem_create() and isc_mem_createx() functions took `max_size`
and `target_size` as first two arguments. Those values were never used in the
BIND 9 code. The refactoring removes those arguments and let BIND 9 always use
the default values.
Previously, the isc_mem_create() and isc_mem_createx() functions could have
failed because of failed memory allocation. As this was no longer true and the
functions have always returned ISC_R_SUCCESS, the have been refactored to return
void.
goto done;
}
- if (isc_mem_create(0, 0, &ctx.mem) != ISC_R_SUCCESS)
- goto done;
+ isc_mem_create(&ctx.mem);
if (isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg) != ISC_R_SUCCESS)
goto done;
%readonly
dns_c_ctx_t *confctx;
};
-
-
-
isc_log_t *lctx;
isc_logconfig_t *lcfg;
- if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) ||
- isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
+ isc_mem_create(&mctx);
+ if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
oops_it_didnt_work();
3) Initalize any additional libraries. The convention for the name of
To create a basic memory context, use:
isc_mem_t *mctx = NULL;
- result = isc_mem_create(0, 0, &mctx);
+ isc_mem_create(&mctx);
(The zeroes are tuning parameters, `max_size` and `target_size`: Any
allocations smaller than `max_size` will be satisfied by getting
isc_log_t *lctx;
isc_logconfig_t *lcfg;
- if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) ||
- isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
+ isc_mem_create(&mctx);
+ if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) {
oops_it_didnt_work();
+ }
1. Initalize any additional libraries. The convention for the name of
the initialization function is `{library}_log_init()`, with a pointer to
} while (0)
/*@{*/
-isc_result_t
-isc_mem_create(size_t max_size, size_t target_size,
- isc_mem_t **mctxp);
+void
+isc_mem_create(isc_mem_t **mctxp);
-isc_result_t
-isc_mem_createx(size_t max_size, size_t target_size,
- isc_memalloc_t memalloc, isc_memfree_t memfree,
+void
+isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree,
void *arg, isc_mem_t **mctxp, unsigned int flags);
/*!<
* \brief Create a memory context.
*
- * 'max_size' and 'target_size' are tuning parameters. When
- * ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
- * will be satisfied by getting blocks of size 'target_size' from the
- * system allocator and breaking them up into pieces; larger allocations
- * will use the system allocator directly. If 'max_size' and/or
- * 'target_size' are zero, default values will be * used. When
- * ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
- *
- * 'max_size' is also used to size the statistics arrays and the array
- * used to record active memory when ISC_MEM_DEBUGRECORD is set. Setting
- * 'max_size' too low can have detrimental effects on performance.
- *
* A memory context created using isc_mem_createx() will obtain
* memory from the system by calling 'memalloc' and 'memfree',
* passing them the argument 'arg'. A memory context created
* Public.
*/
-isc_result_t
-isc_mem_createx(size_t init_max_size, size_t target_size,
- isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
+void
+isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
isc_mem_t **ctxp, unsigned int flags)
{
isc__mem_t *ctx;
isc_mutex_init(&ctx->lock);
}
- if (init_max_size == 0U)
- ctx->max_size = DEF_MAX_SIZE;
- else
- ctx->max_size = init_max_size;
+ ctx->max_size = DEF_MAX_SIZE;
ctx->flags = flags;
isc_refcount_init(&ctx->references, 1);
memset(ctx->name, 0, sizeof(ctx->name));
ctx->maxmalloced += (ctx->max_size+1) * sizeof(struct stats);
if ((flags & ISC_MEMFLAG_INTERNAL) != 0) {
- if (target_size == 0U)
- ctx->mem_target = DEF_MEM_TARGET;
- else
- ctx->mem_target = target_size;
+ ctx->mem_target = DEF_MEM_TARGET;
ctx->freelists = (memalloc)(arg, ctx->max_size *
sizeof(element *));
RUNTIME_CHECK(ctx->freelists != NULL);
UNLOCK(&contextslock);
*ctxp = (isc_mem_t *)ctx;
-
- return (ISC_R_SUCCESS);
}
static void
}
#endif /* HAVE_JSON_C */
-isc_result_t
-isc_mem_create(size_t init_max_size, size_t target_size, isc_mem_t **mctxp) {
- return (isc_mem_createx(init_max_size, target_size,
- default_memalloc, default_memfree,
- NULL, mctxp, isc_mem_defaultflags));
+void
+isc_mem_create(isc_mem_t **mctxp) {
+ isc_mem_createx(default_memalloc, default_memfree,
+ NULL, mctxp, isc_mem_defaultflags);
}
void *