24 lines
725 B
C
24 lines
725 B
C
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
/* Count on the pool to reject a request larger than its region. Link wydealloc. */
|
|
#include <wydealloc.h>
|
|
#include <cmoc.h>
|
|
|
|
static unsigned char storage[64];
|
|
|
|
int main(void)
|
|
{
|
|
MemPool pool;
|
|
void *small, *tooBig;
|
|
if (!MemPool_init(&pool, storage, storage + sizeof(storage)))
|
|
return 1;
|
|
small = MemPool_alloc(&pool, 8);
|
|
tooBig = MemPool_alloc(&pool, 80);
|
|
printf("SMALL %s, LARGE %s\n", small ? "OK" : "FAILED", tooBig ? "OK" : "REFUSED");
|
|
MemPool_free(&pool, small);
|
|
MemPool_free(&pool, tooBig);
|
|
small = MemPool_alloc(&pool, 8);
|
|
printf("AFTER FREE: %s\n", small ? "OK" : "FAILED");
|
|
MemPool_free(&pool, small);
|
|
return 0;
|
|
}
|