Annotation of libelwix/example/test_mem.c, revision 1.1
1.1 ! misho 1: #include <stdio.h>
! 2: #include <stdlib.h>
! 3: #include <elwix.h>
! 4:
! 5:
! 6: void show(u_int size, u_int act, u_int inact)
! 7: {
! 8: if (!act && !inact)
! 9: return;
! 10:
! 11: if (size < 1024)
! 12: printf("Statistics:: BUCKET %uB size, %u active, %u inactive\n", size, act, inact);
! 13: else if (size < 1024 * 1024)
! 14: printf("Statistics:: BUCKET %uKB size, %u active, %u inactive\n", size / 1024, act, inact);
! 15: else
! 16: printf("Statistics:: BUCKET %uMB size, %u active, %u inactive\n", size / (1024 * 1024), act, inact);
! 17: }
! 18:
! 19: int
! 20: main(int argc, char **argv)
! 21: {
! 22: mpool_t *mp;
! 23: void *addr;
! 24: int i;
! 25: u_long curr;
! 26:
! 27: for (i = 0; i < 3; i++) {
! 28: addr = malloc(4000);
! 29: printf("addr=%p\n", addr);
! 30: free(addr);
! 31: }
! 32:
! 33: mp = mpool_init(0);
! 34: if (!mp) {
! 35: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
! 36: return 1;
! 37: }
! 38: /*
! 39: mpool_getquota(mp, &curr, NULL);
! 40: printf("___current=%lu\n", curr);
! 41: */
! 42:
! 43: for (i = 0; i < 3; i++) {
! 44: addr = mpool_malloc(mp, 4000, "mdaaa 4000");
! 45: if (!addr) {
! 46: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
! 47: mpool_destroy(&mp);
! 48: return 2;
! 49: }
! 50: printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
! 51:
! 52: strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n",
! 53: mpool_getsizebyaddr(addr));
! 54: // mpool_free(mp, addr, 0);
! 55: }
! 56:
! 57: mpool_getquota(mp, &curr, NULL);
! 58: printf("___current=%lu\n", curr);
! 59:
! 60: printf("0) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 61: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 62: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
! 63: mpool_statistics(mp, show);
! 64:
! 65: addr = mpool_realloc(mp, addr, 5010, "|||||||||||||");
! 66: if (!addr)
! 67: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
! 68: mpool_getquota(mp, &curr, NULL);
! 69: printf("addr=%p_current=%lu\n", addr, curr);
! 70:
! 71: printf("1) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 72: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 73: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
! 74: mpool_statistics(mp, show);
! 75:
! 76:
! 77: if (addr)
! 78: mpool_free(mp, addr, 0);
! 79:
! 80: printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 81: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 82: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
! 83: mpool_statistics(mp, show);
! 84:
! 85: mpool_purge(mp, 0);
! 86:
! 87: mpool_getquota(mp, &curr, NULL);
! 88: printf("___current=%lu\n", curr);
! 89:
! 90: printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 91: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 92: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
! 93: mpool_statistics(mp, show);
! 94:
! 95: addr = mpool_malloc(mp, 4000, "mdaaa 4000");
! 96: if (!addr) {
! 97: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
! 98: mpool_destroy(&mp);
! 99: return 2;
! 100: }
! 101: printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
! 102: mpool_free(mp, addr, 0);
! 103:
! 104: printf("4) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 105: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 106: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
! 107: mpool_statistics(mp, show);
! 108: mpool_destroy(&mp);
! 109: return 0;
! 110: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>