1 #include <aros/debug.h>
2 #include <proto/exec.h>
7 * Re-define output to bug in order to get exact measurements.
8 * Console's history consumes memory, so this may look like a
19 /* We Forbid() in order to see how our allocations influence free memory size */
22 output("Available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
24 pool
= CreatePool(MEMF_ANY
, 4096, 4096);
25 output("Created pool 0x%p, available memory: %lu bytes\n", pool
, (unsigned long)AvailMem(MEMF_ANY
));
30 output("Failed to create pool!\n");
34 output("Available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
36 output("Allocating 200 small chunks...\n");
37 for (i
= 0; i
< 200; i
++)
39 chunks
[i
] = AllocPooled(pool
, 50);
42 output("Failed to allocate chunk %u!\n", i
);
46 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
48 output("Now freeing them...\n");
49 for (i
= 0; i
< 200; i
++)
53 FreePooled(pool
, chunks
[i
], 50);
55 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
57 output("Now allocating the whole puddle...\n");
58 chunks
[0] = AllocPooled(pool
, 4096);
59 output("Allocated at 0x%p, available memory: %lu bytes\n", chunks
[0], (unsigned long)AvailMem(MEMF_ANY
));
61 output("Now allocating a BIG chunk...\n");
62 chunks
[1] = AllocPooled(pool
, 16384);
63 output("Allocated at 0x%p, available memory: %lu bytes\n", chunks
[1], (unsigned long)AvailMem(MEMF_ANY
));
65 output("Freeing both chunks...\n");
66 FreePooled(pool
, chunks
[0], 4096);
67 FreePooled(pool
, chunks
[1], 16384);
69 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
71 output("Now attempting to re-allocate big chunk...\n");
72 chunks
[1] = AllocPooled(pool
, 16384);
73 output("Allocated at 0x%p, available memory: %lu bytes\n", chunks
[1], (unsigned long)AvailMem(MEMF_ANY
));
75 output("Freeing the whole pool...\n");
77 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));