Date: Thu, 20 May 2004 01:42:00 -0500 From: Dan Nelson <dnelson@allantgroup.com> To: freebsd-questions@freebsd.org Subject: Re: memory allocation/deallocation (malloc experts needed) Message-ID: <20040520064200.GB86452@dan.emsphone.com> In-Reply-To: <20040520050918.GA85327%till@score.is.tsukuba.ac.jp> References: <20040520050918.GA85327%till@score.is.tsukuba.ac.jp>
next in thread | previous in thread | raw e-mail | index | archive | help
--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In the last episode (May 20), Till Plewe said:
> My problem is essentially that freeing large numbers of small chunks
> of memory can be very slow. I have run into this problem twice so
> far.
Do you have a testcase? The attached program mallocs 1 million
128-byte blocks, then frees them. With MALLOC_OPTIONS set to jz (i.e.
no filling of freed memory), it takes .184 seconds to free them all.
With it set to J, it takes 1 second.
CPU: Intel Pentium III (909.96-MHz 686-class CPU)
--
Dan Nelson
dnelson@allantgroup.com
--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="malloctime.c"
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>
#define NUM 1048576
#define SIZE 128
void *mypointers[NUM];
struct timeval elap;
struct rusage r_s, r_e;
int main(void)
{
int i;
printf("malloc:");
fflush(stdout);
for (i = 0; i < NUM; i++)
{
mypointers[i] = malloc(SIZE);
}
printf("done.\nfree:");
fflush(stdout);
getrusage(RUSAGE_SELF, &r_s);
for (i = 0; i < NUM; i++)
{
free(mypointers[i]);
}
getrusage(RUSAGE_SELF, &r_e);
timersub(&r_e.ru_utime, &r_s.ru_utime, &elap);
printf("done. %ld.%06ld\n", elap.tv_sec, elap.tv_usec);
return 0;
}
--/04w6evG8XlLl3ft--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040520064200.GB86452>
