3 * gcc test1.c mpool.c -o test1 -Wall -W -Wextra -ansi -pedantic
17 /* Initialize memory pool with 1024 bytes */
18 mpret
= mpool_init(&mpool
, 10, 5);
19 if (mpret
== MPOOL_ENOMEM
) {
20 fprintf(stderr
, "mpool: not enough memory\n");
23 else if (mpret
== MPOOL_ERANGE
) {
24 fprintf(stderr
, "mpool: out of range in mpool_init()\n");
27 else if (mpret
== MPOOL_EBADVAL
) {
28 fprintf(stderr
, "mpool: bad value passed to mpool_init()\n");
32 /* Allocate 32 bytes for buffer */
33 if ((buffer
= mpool_alloc(mpool
, 5)) == NULL
) {
34 fprintf(stderr
, "mpool: no available block in pool\n");
39 /* Read input from standard input stream */
40 fgets(buffer
, 1<<5, stdin
);
42 /* Print buffer's contents */
43 printf("Buffer: %s", buffer
);
47 * could be omitted, since we call mpool_destroy() afterwards
49 mpool_free(mpool
, buffer
);
51 /* Destroy memory pool and free all resources */