I'm sorry to post it for third time, but I haven't received any
helpful advice.
Is it too simple and nooby? Could you please just give me link to
the similar code/discussion?
Q: Why filling assoc.array in shared library freeze execution?
Try to run test_dll_exe.exe several times:
----
// test_dll.d
import std.stdio;
import core.sys.windows.windows;
import core.sys.windows.dll;
mixin SimpleDllMain;
extern(C) {
export void TestFun() {
double[int] T;
foreach (i; 0..10_000_000) {
writefln("i:%d",i);
T[i] = i*1.0;
}
}
}
----
// test_dll_exe.d
import core.runtime;
import core.sys.windows.windows;
import std.exception;
void main() {
HMODULE test_dll = cast(HMODULE)
enforce(Runtime.loadLibrary("test_dll.dll"));
alias extern(C) void function() Test_type;
Test_type TestFun = cast(Test_type)
enforce(GetProcAddress(test_dll, "TestFun"));
TestFun();
}
----
Problem reproduces with dmd 2.095.0 and ldc2 1.24 on Windows 7
SP1, Intel i7 4790.
Compile options:
dmd -m64 -shared -oftest_dll.dll -L/DLL test_dll.d
dmd -m64 test_dll_exe.d
or
ldc2.exe --m64 --shared --of=test_dll.dll -L=/DLL test_dll.d
ldc2.exe --m64 test_dll_exe.d
If I replace double[int] T with array double[] T; T ~= i*0.01;
it's still freezes after some iteration. But if I add in last
case T.length = 10_000_000; T[i] = i*0.01; it's doing just fine.
Any ideas? How to allocate memory in shared library properly?