File:
[ELWIX - Embedded LightWeight unIX -] /
libaitio /
example /
Attic /
test_mem.c
Revision
1.2:
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Jul 3 08:51:04 2012 UTC (12 years, 1 month ago) by
misho
Branches:
MAIN
CVS tags:
io5_0,
io4_1,
io4_0,
io3_9,
io3_8,
io3_7,
io3_6,
io3_5,
io3_4,
io3_3,
io3_2,
IO4_1,
IO4_0,
IO3_9,
IO3_8,
IO3_7,
IO3_6,
IO3_5,
IO3_4,
IO3_3,
IO3_2,
IO3_1,
HEAD
version 3.1
#include <stdio.h>
#include <aitio.h>
void show(u_int size, u_int act, u_int inact)
{
if (!act && !inact)
return;
if (size < 1024)
printf("Statistics:: BUCKET %uB size, %u active, %u inactive\n", size, act, inact);
else if (size < 1024 * 1024)
printf("Statistics:: BUCKET %uKB size, %u active, %u inactive\n", size / 1024, act, inact);
else
printf("Statistics:: BUCKET %uMB size, %u active, %u inactive\n", size / (1024 * 1024), act, inact);
}
int
main(int argc, char **argv)
{
mpool_t *mp;
void *addr;
int i;
u_long curr;
for (i = 0; i < 3; i++) {
addr = malloc(4000);
printf("addr=%p\n", addr);
free(addr);
}
mp = mpool_init(0);
if (!mp) {
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
return 1;
}
/*
mpool_getquota(mp, &curr, NULL);
printf("___current=%lu\n", curr);
*/
for (i = 0; i < 3; i++) {
addr = mpool_malloc(mp, 4000, "mdaaa 4000");
if (!addr) {
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
mpool_destroy(&mp);
return 2;
}
printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n",
mpool_getsizebyaddr(addr));
// mpool_free(mp, addr, 0);
}
mpool_getquota(mp, &curr, NULL);
printf("___current=%lu\n", curr);
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_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
mpool_statistics(mp, show);
addr = mpool_realloc(mp, addr, 5010, "|||||||||||||");
if (!addr)
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
mpool_getquota(mp, &curr, NULL);
printf("addr=%p_current=%lu\n", addr, curr);
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_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
mpool_statistics(mp, show);
if (addr)
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",
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);
mpool_purge(mp, 0);
mpool_getquota(mp, &curr, NULL);
printf("___current=%lu\n", curr);
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_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
mpool_statistics(mp, show);
addr = mpool_malloc(mp, 4000, "mdaaa 4000");
if (!addr) {
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
mpool_destroy(&mp);
return 2;
}
printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
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",
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);
mpool_destroy(&mp);
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>