forked from dcshi/ncx_mempool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
53 lines (44 loc) · 886 Bytes
/
main.c
File metadata and controls
53 lines (44 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "ncx_slab.h"
int main(int argc, char **argv)
{
char *p;
size_t pool_size = 4096000; //4M
ncx_slab_stat_t stat;
u_char *space;
space = (u_char *)malloc(pool_size);
ncx_slab_pool_t *sp;
sp = (ncx_slab_pool_t*) space;
sp->addr = space;
sp->min_shift = 3;
sp->end = space + pool_size;
ncx_slab_init(sp);
int i;
for (i = 0; i < 1000000; i++)
{
p = ncx_slab_alloc(sp, 128 + i);
if (p == NULL)
{
printf("%d\n", i);
return -1;
}
ncx_slab_free(sp, p);
}
ncx_slab_stat(sp, &stat);
printf("##########################################################################\n");
for (i = 0; i < 2500; i++)
{
p = ncx_slab_alloc(sp, 30 + i);
if (p == NULL)
{
printf("%d\n", i);
return -1;
}
if (i % 3 == 0)
{
ncx_slab_free(sp, p);
}
}
ncx_slab_stat(sp, &stat);
free(space);
return 0;
}