2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
7 #include <proto/exec.h>
12 * Re-define output to bug in order to get exact measurements.
13 * Console's history consumes memory, so this may look like a
24 /* We Forbid() in order to see how our allocations influence free memory size */
27 output("Available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
29 pool
= CreatePool(MEMF_ANY
, 4096, 4096);
30 output("Created pool 0x%p, available memory: %lu bytes\n", pool
, (unsigned long)AvailMem(MEMF_ANY
));
35 output("Failed to create pool!\n");
39 output("Available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
41 output("Allocating 200 small chunks...\n");
42 for (i
= 0; i
< 200; i
++)
44 chunks
[i
] = AllocPooled(pool
, 50);
47 output("Failed to allocate chunk %u!\n", i
);
51 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
53 output("Now freeing them...\n");
54 for (i
= 0; i
< 200; i
++)
58 FreePooled(pool
, chunks
[i
], 50);
60 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
62 output("Now allocating the whole puddle...\n");
63 chunks
[0] = AllocPooled(pool
, 4096);
64 output("Allocated at 0x%p, available memory: %lu bytes\n", chunks
[0], (unsigned long)AvailMem(MEMF_ANY
));
66 output("Now allocating a BIG chunk...\n");
67 chunks
[1] = AllocPooled(pool
, 16384);
68 output("Allocated at 0x%p, available memory: %lu bytes\n", chunks
[1], (unsigned long)AvailMem(MEMF_ANY
));
70 output("Freeing both chunks...\n");
71 FreePooled(pool
, chunks
[0], 4096);
72 FreePooled(pool
, chunks
[1], 16384);
74 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
76 output("Now attempting to re-allocate big chunk...\n");
77 chunks
[1] = AllocPooled(pool
, 16384);
78 output("Allocated at 0x%p, available memory: %lu bytes\n", chunks
[1], (unsigned long)AvailMem(MEMF_ANY
));
80 output("Freeing the whole pool...\n");
82 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));