mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
9fefe9b291
git-svn-id: file:///svn/tokudb@469 c7de825b-a66e-492c-adef-691d508d4ae1
52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include "memory.h"
|
|
#include "mempool.h"
|
|
|
|
void test_mempool_limits(int size) {
|
|
void *base = malloc(size);
|
|
struct mempool mempool;
|
|
mempool_init(&mempool, base, size);
|
|
|
|
int i;
|
|
for (i=0;; i++) {
|
|
void *vp = mempool_malloc(&mempool, 1, 1);
|
|
if (vp == 0)
|
|
break;
|
|
}
|
|
assert(i == size);
|
|
|
|
mempool_fini(&mempool);
|
|
free(base);
|
|
}
|
|
|
|
void test_mempool_malloc_mfree(int size) {
|
|
void *base = malloc(size);
|
|
struct mempool mempool;
|
|
mempool_init(&mempool, base, size);
|
|
|
|
void *vp[size];
|
|
int i;
|
|
for (i=0;; i++) {
|
|
vp[i] = mempool_malloc(&mempool, 1, 1);
|
|
if (vp[i] == 0)
|
|
break;
|
|
}
|
|
assert(i == size);
|
|
|
|
for (i=0; i<size; i++)
|
|
mempool_mfree(&mempool, vp[i], 1);
|
|
assert(mempool_get_frag_size(&mempool) == size);
|
|
|
|
mempool_fini(&mempool);
|
|
free(base);
|
|
}
|
|
|
|
int main() {
|
|
test_mempool_limits(0);
|
|
test_mempool_limits(256);
|
|
test_mempool_malloc_mfree(0);
|
|
test_mempool_malloc_mfree(256);
|
|
return 0;
|
|
}
|