Copyright clean-up (part 1):
[AROS.git] / test / exec / pool.c
blobc775690d0145e13cd765b2952df93c42a377774e
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <proto/exec.h>
9 #include <stdio.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
14 * memory leak.
16 #define output printf
18 int main(void)
20 APTR chunks[200];
21 APTR pool;
22 int i;
24 /* We Forbid() in order to see how our allocations influence free memory size */
25 Forbid();
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));
32 if (!pool)
34 Permit();
35 output("Failed to create pool!\n");
36 return 1;
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);
45 if (!chunks[i])
47 output("Failed to allocate chunk %u!\n", i);
48 break;
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++)
56 if (!chunks[i])
57 break;
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");
81 DeletePool(pool);
82 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY));
84 Permit();
85 return 0;