[BusyBox] should xmalloc clear memmory ?

Vladimir N. Oleynik dzo at simtreas.ru
Sun Feb 11 13:21:53 UTC 2001


Glenn McGrath wrote:
> 
> >Using grep memset -r *|wc -l
> 
> there are 75 places where we use memset, 5 of them dont set it to 0,
> probably a lot of the remaining 70 are happening imediately after
> xmalloc.
> 
> So, if we cleared memory inside xmalloc we could remove upto 70
> statments.
> 
> Would this be a bad idea for any reason ?

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main()
{
        char *p;
        char sz[16];
        time_t t1, t2;
        long sl;

        fprintf(stderr, "Size (M): ");
        fgets(sz, sizeof(sz), stdin);
        sl=atol(sz)*1024*1024;

        p = malloc(sl);
        if(p==0) {
                fprintf(stderr, "malloc returned 0\n");
                return 1;
        }

        fprintf(stderr, "Swaping...");

        time(&t1);
        memset(p, 0, sl);
        time(&t2);

        fprintf(stderr, "\nSwaping running %.0lf seconds\n", difftime(t2,
t1));
}


Result:
Size (M): 100
Swaping...
Swaping running 8 seconds

:(


Require hard individuale analize.
But yor idea not bad. :)



--w
vodz





More information about the busybox mailing list