12 /* Initialize memory pool with 1024 bytes */
13 mpret
= mpool_init(&mpool
, 10, 5);
14 if (mpret
== MPOOL_ENOMEM
) {
15 fprintf(stderr
, "mpool: not enough memory\n");
18 else if (mpret
== MPOOL_EBADVAL
) {
19 fprintf(stderr
, "mpool: bad value passed to mpool_init()\n");
23 /* Allocate 32 bytes for buffer */
24 if ((buffer
= mpool_alloc(mpool
, 5)) == NULL
) {
25 fprintf(stderr
, "mpool: no available block in pool\n");
30 /* Read input from standard input stream */
31 fgets(buffer
, 1<<5, stdin
);
33 /* Print buffer's contents */
34 printf("Buffer: %s", buffer
);
38 * could be omitted, since we call mpool_destroy() afterwards
40 mpool_free(mpool
, buffer
);
42 /* Destroy memory pool and free all resources */