dmd memory usage/static lib/algorithm bug?
Marek Janukowicz
marek at janukowicz.net
Wed Aug 28 08:29:40 PDT 2013
This is really a cross-domain issue, but I didn't feel like splitting it
into separate posts would make sense.
I use DMD 2.063.2 on Linux 64-bit.
I have some code in my (non-trivial) application that basically corresponds
to this:
import std.stdio, std.algorithm, std.array;
void main () {
struct Val {
int i;
}
Val[] arr;
arr ~= Val( 3 );
arr ~= Val( 1 );
arr ~= Val( 2 );
auto sorter = (Val a, Val b) { return a.i < b.i; };
writefln( "sorted: %s", arr.sort!(sorter));
}
While this simple example works, I'm getting segfaults with corresponding
code in thisi bigger project. Those segfaults can be traced down to
algorithm.d line 8315 or another line (8358?) that use this "sorter" lambda
I passed to "sort!" - suggesting it is a bad memory reference.
I tried to create a simple test case that would fail similarly, but to no
avail. I can't make the code for my whole project available, so let's just
say it's either some bug in DMD or something caused by my limited knowledge
of D.
Now the funny things begin: I copied algorithm.d to my project in an attempt
to make some modifications to it (hopefully to fix the problem or at least
get some insight into its nature), but things miraculously started working!
This leads me to the suspicion there is something wrong with libphobos2.a
file provided with DMD tarball.
Next problem in the line is that compilation of my project with algorithm.d
included takes almost 4GB of RAM. While I'm aware of the fact DMD
deliberately doesn't free the memory for performance purposes, this makes
the compilation fail due to insufficient memory on machines with 4GB RAM
(and some taken).
So my questions are:
- how can I limit DMD memory usage?
- how can I include a static library with my project? I can compile
algorithm.d to a static lib, but how do I include this one explicitly with
my project while the rest of Phobos should be taken from the stock
libphobos2.a ?
- any other ideas how to solve my problems on any level?
--
Marek Janukowicz
More information about the Digitalmars-d-learn
mailing list