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