}
}
+knot_mm_t * mm_ctx_mempool2(size_t chunk_size)
+{
+ knot_mm_t pool_tmp;
+ mm_ctx_mempool(&pool_tmp, chunk_size);
+ knot_mm_t *pool = mm_alloc(&pool_tmp, sizeof(*pool));
+ if (!pool) {
+ mp_delete(pool_tmp.ctx);
+ return NULL;
+ }
+ memcpy(pool, &pool_tmp, sizeof(*pool));
+ return pool;
+}
+
mm->free = free;
}
+/*! \brief New memory pool context, allocated on itself. */
+KR_EXPORT knot_mm_t * mm_ctx_mempool2(size_t chunk_size);
+
}
struct io_stream_data *io_tty_alloc_data() {
- knot_mm_t _pool = {
- .ctx = mp_new(4096),
- .alloc = (knot_mm_alloc_t) mp_alloc,
- };
- knot_mm_t *pool = mm_alloc(&_pool, sizeof(*pool));
+ knot_mm_t *pool = mm_ctx_mempool2(MM_DEFAULT_BLKSIZE);
if (!pool) {
return NULL;
}
- memcpy(pool, &_pool, sizeof(*pool));
-
struct io_stream_data *data = mm_alloc(pool, sizeof(struct io_stream_data));
data->buf = mp_start(pool->ctx, 512);
};
module->props = props;
- /* Create pool and copy itself */
- knot_mm_t _pool = {
- .ctx = mp_new(4096),
- .alloc = (knot_mm_alloc_t) mp_alloc
- };
- knot_mm_t *pool = mm_alloc(&_pool, sizeof(*pool));
+ knot_mm_t *pool = mm_ctx_mempool2(MM_DEFAULT_BLKSIZE);
if (!pool) {
return kr_error(ENOMEM);
}
- memcpy(pool, &_pool, sizeof(*pool));
-
struct hints_data *data = mm_alloc(pool, sizeof(struct hints_data));
if (!data) {
mp_delete(pool->ctx);