#include #include #define BLOCKSZ 4096 int main (int argc, char *argv[]) { int i, j; void *p; /* make some chaos in the heap */ for (i = 0; i < 1000; i++) for (j = 0; j < 1024; j++) { p = malloc (j); if (((i + j) & 7) == 0) free (p); } /* test */ for (i = 0; i < 16; i++) if (!posix_memalign (&p, BLOCKSZ, BLOCKSZ - sizeof (long))) printf ("%p\n", p); printf ("--\n"); /* make even more chaos with larger chunks */ for (i = 0; i < 1000; i++) { p = malloc (i * 1000); if ((i & 7) == 0) free (p); } /* test again */ for (i = 0; i < 16; i++) if (!posix_memalign (&p, BLOCKSZ, BLOCKSZ - sizeof (long))) printf ("%p\n", p); return 0; }