Hello!

On Wed, May 25, 2005 at 03:17:59PM +0200, Janne Johansson wrote:
>[...]

>This would make all 4/8-byte mallocs take up one page(4k) each if I
>understand this correctly.

>That's fine for debugging, but probably too expensive for normal usage.

I tend to agree. While most applications will allocate 4/8 byte values
either as local variables or as part of something bigger, you can't
exclude cases where generic code could hit that case in masses.

Take for example a list of variable-length lists of integers:

        int **list;
        int *sizes;

        sizes = (int *) malloc(lines * sizeof(int));
        list = (int **) malloc(lines * sizeof(int*));

        /* error checking, of course */

        for (i = 0; i < lines; ++ i) {
                sizes[i] = choose_size(i);
                list[i] = (int *) malloc(sizes[i] * sizeof(int));
                choose_values(list[i], sizes[i]);
        }

Now if the sizes returned by choose_size are in a distribution with
an average of a few (say 4), but with a big variation, a size of 1 might
occur often enough, i.e. you might waste *much* memory and time (mmap of
single pages might well hit the kernel much).

That's why I tend to agree, very cool idea for debugging (like it seems
to be now, with the flag "G"), but not a low enough overhead for full
production use (*un*like things like propolice etc.).

Kind regards,

Hannah.

Reply via email to