My question is similar to this one here, but there are some difference.
I have a fortran dll as the backend, and a C# exe as the front end. I use PInvoke to pass data between them.
There are 22 parameters between the C# and the fortran code. And some of them are integer, double, pointers ( C# pointers), array and whatnot. So it's a mix of types.
The problem is that for small arrays, the code works fine, however, for large arrays (~10k element size), a stackoverflowexception was thrown right after my code enters into the managed code.
Edit: I've managed to scale down everything. Here's the fortran code:
subroutine chartest(maxncv,ldv)
!DEC$ ATTRIBUTES DLLEXPORT::chartest
!DEC$ ATTRIBUTES ALIAS:'chartest'::chartest
!DEC$ ATTRIBUTES VALUE :: maxncv,ldv
&
integer, intent(in) :: maxncv, ldv
Double precision
& v(ldv,maxncv),d(maxncv,2)
print *, 'hello'
end
And here's my C# declaration:
public static extern void chartest(
[MarshalAs(UnmanagedType.I4)] int maxncv,
[MarshalAs(UnmanagedType.I4)] int ldv
);
If I call chartest(546, 547)
, I would get a stackoverflowexception.
546*547=298662
, that doesn't seem like a lot of element, no?