version 1.1.1.1, 2013/01/17 10:05:35
|
version 1.6.2.1, 2024/08/14 16:01:10
|
Line 1
|
Line 1
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <string.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <elwix.h> |
#include <elwix.h> |
|
|
|
|
void show(u_int size, u_int act, u_int inact) | int show(unsigned int size, unsigned int act, unsigned int inact, void *data, unsigned int dlen) |
{ |
{ |
if (!act && !inact) |
if (!act && !inact) |
return; | return -1; |
|
|
if (size < 1024) |
if (size < 1024) |
printf("Statistics:: BUCKET %uB size, %u active, %u inactive\n", size, act, inact); |
printf("Statistics:: BUCKET %uB size, %u active, %u inactive\n", size, act, inact); |
Line 14 void show(u_int size, u_int act, u_int inact)
|
Line 15 void show(u_int size, u_int act, u_int inact)
|
printf("Statistics:: BUCKET %uKB size, %u active, %u inactive\n", size / 1024, act, inact); |
printf("Statistics:: BUCKET %uKB size, %u active, %u inactive\n", size / 1024, act, inact); |
else |
else |
printf("Statistics:: BUCKET %uMB size, %u active, %u inactive\n", size / (1024 * 1024), act, inact); |
printf("Statistics:: BUCKET %uMB size, %u active, %u inactive\n", size / (1024 * 1024), act, inact); |
|
|
|
return 0; |
} |
} |
|
|
int |
int |
Line 22 main(int argc, char **argv)
|
Line 25 main(int argc, char **argv)
|
mpool_t *mp; |
mpool_t *mp; |
void *addr; |
void *addr; |
int i; |
int i; |
u_long curr; | u_long curr, real; |
|
|
|
printf("whether default memory mapper is elwix? %d\n", elwix_mm_inuse()); |
|
|
for (i = 0; i < 3; i++) { |
for (i = 0; i < 3; i++) { |
addr = malloc(4000); |
addr = malloc(4000); |
printf("addr=%p\n", addr); |
printf("addr=%p\n", addr); |
Line 36 main(int argc, char **argv)
|
Line 41 main(int argc, char **argv)
|
return 1; |
return 1; |
} |
} |
/* |
/* |
mpool_getquota(mp, &curr, NULL); | mpool_getquota(mp, &curr, NULL, NULL); |
printf("___current=%lu\n", curr); |
printf("___current=%lu\n", curr); |
*/ |
*/ |
|
|
|
printf(">>> get 3 allocs\n"); |
for (i = 0; i < 3; i++) { |
for (i = 0; i < 3; i++) { |
addr = mpool_malloc(mp, 4000, "mdaaa 4000"); |
addr = mpool_malloc(mp, 4000, "mdaaa 4000"); |
if (!addr) { |
if (!addr) { |
Line 51 main(int argc, char **argv)
|
Line 57 main(int argc, char **argv)
|
|
|
strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n", |
strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n", |
mpool_getsizebyaddr(addr)); |
mpool_getsizebyaddr(addr)); |
// mpool_free(mp, addr, 0); | mpool_free(mp, addr, 0); |
} |
} |
|
|
mpool_getquota(mp, &curr, NULL); | mpool_getquota(mp, &curr, &real, NULL); |
printf("___current=%lu\n", curr); | printf("___current=%lu ___real=%lu\n", curr, real); |
|
|
printf("0) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
printf("0) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mpool_statistics(mp, show); | mpool_statistics(mp, show, NULL, 0); |
|
|
|
printf(">>> realloc 4000 to 5010 addr=%p\n", addr); |
addr = mpool_realloc(mp, addr, 5010, "|||||||||||||"); |
addr = mpool_realloc(mp, addr, 5010, "|||||||||||||"); |
if (!addr) |
if (!addr) |
printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError()); |
printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError()); |
mpool_getquota(mp, &curr, NULL); | mpool_getquota(mp, &curr, &real, NULL); |
printf("addr=%p_current=%lu\n", addr, curr); | printf("addr=%p_current=%lu_real=%lu\n", addr, curr, real); |
|
|
printf("1) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
printf("1) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mpool_statistics(mp, show); | mpool_statistics(mp, show, NULL, 0); |
|
|
|
|
|
printf(">>> free addr=%p\n", addr); |
if (addr) |
if (addr) |
mpool_free(mp, addr, 0); |
mpool_free(mp, addr, 0); |
|
|
printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mpool_statistics(mp, show); | mpool_statistics(mp, show, NULL, 0); |
|
|
|
printf(">>> purge inactive memory\n"); |
mpool_purge(mp, 0); |
mpool_purge(mp, 0); |
|
|
mpool_getquota(mp, &curr, NULL); | mpool_getquota(mp, &curr, &real, NULL); |
printf("___current=%lu\n", curr); | printf("___current=%lu ___real=%lu\n", curr, real); |
|
|
printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mpool_statistics(mp, show); | mpool_statistics(mp, show, NULL, 0); |
|
|
|
printf(">>> alloc new 4000\n"); |
addr = mpool_malloc(mp, 4000, "mdaaa 4000"); |
addr = mpool_malloc(mp, 4000, "mdaaa 4000"); |
if (!addr) { |
if (!addr) { |
printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError()); |
printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError()); |
Line 99 main(int argc, char **argv)
|
Line 109 main(int argc, char **argv)
|
return 2; |
return 2; |
} |
} |
printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr)); |
printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr)); |
|
printf(">>> and free new 4000 addr=%p\n", addr); |
mpool_free(mp, addr, 0); |
mpool_free(mp, addr, 0); |
|
|
printf("4) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
printf("4) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
mpool_statistics(mp, show); | mpool_statistics(mp, show, NULL, 0); |
| |
| |
| printf("realloc 4000 to 100000 and to 2000000\n"); |
| addr = mpool_malloc(mp, 4000, "mdaaa 4000"); |
| printf("malloc addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr)); |
| addr = mpool_realloc(mp, addr, 100000, "ohche"); |
| printf("realloc addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr)); |
| addr = mpool_realloc(mp, addr, 2000000, NULL); |
| printf("realloc addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr)); |
| mpool_free(mp, addr, 0); |
| printf("5) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", |
| mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, |
| mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free); |
| mpool_statistics(mp, show, NULL, 0); |
| |
| addr = mpool_calloc(mp, 56, 1, NULL); |
| printf("calloc addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr)); |
| mpool_free(mp, addr, 0); |
| addr = mpool_calloc(mp, 60, 1, "alabala"); |
| printf("calloc addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr)); |
| mpool_free(mp, addr, 0); |
| |
| mpool_dump(mp, NULL); |
mpool_destroy(&mp); |
mpool_destroy(&mp); |
return 0; |
return 0; |
} |
} |