Leopold Toetsch <[EMAIL PROTECTED]> wrote:
>>>... .  We need some tests, from which size memory is
>>>cleard for malloc and memalign.

Here is a small program, which could be put into a test.

Are there systems out there, without memalign, where malloc.c can not be
linked with?

/*
 * test clean memory threshold
 */

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

int main(int argc, char *argv[])
{
    char *buf;
    size_t size;
    int j, u;

    if (argc != 3) {
        printf("usage: test [malloc|memalign] hexsize\n");
        return 1;
    }
    ++argv;
    size = (size_t)strtoul(argv[1], NULL, 16);
    buf = malloc(size);
    for (j = 0; j < size; j++)
        buf[j] = 0xff;
    free(buf);
    if (strcmp(*argv, "malloc") == 0) {
        printf("malloc\nsize\tclean\tadr\n");
        buf = malloc(size);
    }
    else if (strcmp(*argv, "memalign") == 0) {
        printf("memalign\nsize\tclean\tadr\n");
        if (size & (size -1 )) {
            printf("not a power of 2\n");
            return 1;
        }
        buf = memalign(size, size);
    }
    else {
        printf("usage: test [malloc|memalign] size\n");
        return 1;
    }
    for (j = u = 0; j < size; j++)
        if (buf[j]) {
            u = 1;
            break;
        }

    printf("0x%x\t%s\t%p\n",
            size, u ? "n": "y", buf);
    free(buf);
    return 0;
}
/*
 * Local variables:
 * c-indentation-style: bsd
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 *
 * vim: expandtab shiftwidth=4:
*/

leo

Reply via email to