Upload ABIv1 packages into the nightly2 directory during the transition
[AROS.git] / test / exec / allocmem.c
blob922a2e3e558f304324049cad38f907120f34f8ac
1 #include <aros/debug.h>
2 #include <proto/exec.h>
4 #include <stdio.h>
5 #include <string.h>
7 /*
8 * Re-define output to bug in order to get exact measurements.
9 * Console's history consumes memory, so this may look like a
10 * memory leak.
12 #define output printf
14 static BOOL trash = FALSE;
16 static void AccessTest(ULONG *ptr)
18 if (!trash)
19 return;
21 ptr[-1] = 0x40302010; /* This should NOT cause mungwall warning */
22 ptr[0] = 0x01020304; /* This SHOULD produce mungwall warning */
25 int main(int argc, char **argv)
27 APTR block0, start, block1;
30 * Do some memory trashing if started with "trash" argument.
31 * It's not adviced to do this without mungwall enabled.
32 * The actual purpose of this is to test mungwall functionality.
34 if ((argc > 1) && (!strcmp(argv[1], "trash")))
35 trash = TRUE;
37 /* We Forbid() in order to see how our allocations influence free memory size */
38 Forbid();
40 output("Available memory: %u bytes\n", AvailMem(MEMF_ANY));
42 output("Allocating 256 KB...\n");
43 block0 = AllocMem(256 * 1024, MEMF_ANY);
44 output("Allocated at 0x%p, available memory: %u bytes\n", block0, AvailMem(MEMF_ANY));
46 AccessTest(block0 + 256 * 1024);
48 output("Freeing the block...\n");
49 FreeMem(block0, 256 * 1024);
50 output("Done, available memory: %u bytes\n", AvailMem(MEMF_ANY));
52 start = block0 + 1027; /* Add some none-round displacement to make the life harder */
53 output("Now trying AllocAbs() 4 KB at 0x%p\n", start);
54 block1 = AllocAbs(4096, start);
55 output("Allocated at 0x%p, available memory: %u bytes\n", block1, AvailMem(MEMF_ANY));
57 AccessTest(start + 4096);
59 output("Freeing the block...\n");
60 FreeMem(block1, 4096 + start - block1);
61 output("Done, available memory: %u bytes\n", AvailMem(MEMF_ANY));
63 output("Now repeat this AllocAbs(), but free using our requested start address...\n");
64 block1 = AllocAbs(4096, start);
65 output("Allocated at 0x%p, available memory: %u bytes\n", block1, AvailMem(MEMF_ANY));
67 if (block1)
69 AccessTest(start + 4096);
71 output("Freeing the block...\n");
72 FreeMem(start, 4096);
73 output("Done, available memory: %u bytes\n", AvailMem(MEMF_ANY));
76 Permit();
77 return 0;