Annotation of libaitsess/contrib/test_mem.c, revision 1.1.2.6
1.1.2.1 misho 1: #include <stdio.h>
2: #include <aitsess.h>
3:
4:
1.1.2.6 ! misho 5: void show(u_int size, u_int act, u_int inact)
! 6: {
! 7: if (!act && !inact)
! 8: return;
! 9:
! 10: if (size < 1024)
! 11: printf("Statistics:: BUCKET %uB size, %u active, %u inactive\n", size, act, inact);
! 12: else if (size < 1024 * 1024)
! 13: printf("Statistics:: BUCKET %uKB size, %u active, %u inactive\n", size / 1024, act, inact);
! 14: else
! 15: printf("Statistics:: BUCKET %uMB size, %u active, %u inactive\n", size / (1024 * 1024), act, inact);
! 16: }
! 17:
1.1.2.1 misho 18: int
19: main(int argc, char **argv)
20: {
21: mpool_t *mp;
1.1.2.2 misho 22: void *addr;
23: int i;
24:
1.1.2.3 misho 25: for (i = 0; i < 3; i++) {
26: addr = malloc(4000);
27: printf("addr=%p\n", addr);
28: free(addr);
29: }
1.1.2.1 misho 30:
1.1.2.5 misho 31: mp = mpool_init(0);
1.1.2.1 misho 32: if (!mp) {
33: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
34: return 1;
35: }
36:
1.1.2.2 misho 37: for (i = 0; i < 3; i++) {
1.1.2.4 misho 38: addr = mpool_malloc(mp, 4000, "mdaaa 4000");
39: if (!addr) {
40: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
41: mpool_destroy(&mp);
42: return 2;
43: }
44: printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
45:
46: strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n",
47: mpool_getsizebyaddr(addr));
48: // mpool_free(mp, addr, 0);
49: }
50:
1.1.2.6 ! misho 51: printf("1)\n");
! 52: mpool_statistics(mp, show);
! 53:
1.1.2.4 misho 54: mpool_free(mp, addr, 0);
55:
1.1.2.6 ! misho 56: printf("2)\n");
! 57: mpool_statistics(mp, show);
! 58:
1.1.2.4 misho 59: mpool_purge(mp, 0);
60:
1.1.2.6 ! misho 61: printf("3)\n");
! 62: mpool_statistics(mp, show);
! 63:
1.1.2.2 misho 64: addr = mpool_malloc(mp, 4000, "mdaaa 4000");
65: if (!addr) {
66: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
67: mpool_destroy(&mp);
68: return 2;
69: }
70: printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
1.1.2.3 misho 71: mpool_free(mp, addr, 0);
1.1.2.2 misho 72:
1.1.2.6 ! misho 73: printf("Done.\n");
! 74: mpool_statistics(mp, show);
1.1.2.1 misho 75: mpool_destroy(&mp);
76: return 0;
77: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>