Memory allocation in D

"Jérôme M. Berger" jeberger at free.fr
Thu Nov 29 11:58:25 PST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marius Muja wrote:
> Hi,
> 
> I'm working on a program that is computationally and memory intensive. I
> have noticed that if I allocate the memory using D's new operator I can
> allocate only about half as much memory compared to C's malloc (and also
> the memory allocation is much slower). Does anybody know why D's memory
> allocator uses twice as much memory compared to malloc?
> 
> I used the following test program to test this:
> 
> ... snip ...
> 
> When the above program uses the test_d_alloc() function it executes the
> loop about half as many times compared to when it's using the
> test_malloc() function (until it terminates with an out of memory
> error). Also when the allocation is done in smaller increments
> (ALLOC_SIZE is smaller) the test_d_alloc() version segfaults after
> allocating the maximum amount of memory (3G) instead of terminating with
> a nice OutOfMemory error.
> 
	Since you are using Linux, I would like to point out that a call to
malloc may succeed even if there is no memory available at the time.
The program will only fail when it actually tries to access the
memory. Since the D new fills the array with zeroes, it will fail
immediately upon reaching the memory limit. The standard malloc
however may appear to work much longer unless you actually try to
use the memory.

		Jerome
- --
+------------------------- Jerome M. BERGER ---------------------+
|    mailto:jeberger at free.fr      | ICQ:    238062172            |
|    http://jeberger.free.fr/     | Jabber: jeberger at jabber.fr   |
+---------------------------------+------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFHTxnhd0kWM4JG3k8RAuW/AKCBk6hVjvhe/2qLEVdnF1cWvFxEZQCgg0Yu
aVOJuBt6UGLXGiSoQ31EX0I=
=7X3r
-----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list