I left my program open for 9 hours and it used up 700mb of ram, could someone review it?
Vladimir Panteleev via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 27 18:04:03 PST 2015
On Tuesday, 27 January 2015 at 22:39:31 UTC, Gan wrote:
> Would you know why this is using hundreds of mb of rams?
Hi,
What type is CircleShape?
If it is a class, or otherwise contains pointers, then this is
probably the source of your problem.
You are storing high-entropy data (floating-point / random
numbers) within the same type as one containing pointers. This is
problematic with a non-precise GC, because the GC will consider
the random numbers as possibly pointers, thus pinning random
objects within the memory address space.
You should be able to work around this problem by:
- Making CircleShape a static struct without any pointers
- If you need to have pointers associated with CircleShape:
splitting pointers and non-pointers into separate arrays of
structs
- Manually managing memory allocations, and storing the
CircleShape instances outside the managed D heap
- Building your program for x86_64 - 64 bits of address space
will make fake pointer pinning very unlikely
- Using a precise GC - none are currently available for D, but
one is under development:
https://github.com/D-Programming-Language/druntime/pull/1057
More information about the Digitalmars-d-learn
mailing list