Hello everyone! I want to create shared library that buffer some data and do some calculations, another program will use it. I wonder how this simplest code lead to crash (freeze) of dll:
---
// test_dll.d
import std.stdio;
import std.file;
import core.runtime;
import core.sys.windows.windows;
import std.exception;

version (test_dll) {
extern(C) {

export void TestFun() {
    double[int] T;
    foreach (i; 0..10000000) {
        writefln("i:%d",i);
        T[i] = i*1.0;
    }
}

} // extern(C)
} // version (test_dll)

version (test_exe) {
void main(string[] args) {
    if (!"test_dll.dll".exists) {
        writeln("test_dll.dll not exists");
    }

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();
} // main
} // version (stec_app)
---
Code compiled with options (version of dmd - 2.095.0, Windows 7 SP1, Intel Core i7 4790): dmd -m64 -version=test_dll -shared -oftest_dll.dll -L/DLL test_dll.d dll.d
dmd -m64 -version=test_exe test_dll.d
Here dll.d - usual wrapper for DllMain (https://wiki.dlang.org/Win32_DLLs_in_D).

Any ideas? How to allocate memory in shared library properly?

Reply via email to