Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Allocatable array in DLL

bendel_boy_2007
Beginner
416 Views

I have a DLL, with a stub along the lines of

sub DoStuff(iStatus)

double precision, allocatable:: work(:)

if (iStatus .eq. 1) then

allocate(work(mySize), STAT = iDid)

elseif (iiStatus .eq. 2) then

deallocate(work, STAT = iDid)

endif

The allocation works. When the subroutine is called a second time, the work array has been deallocated. I thought that an allocated array stayed allocated until an explicit deallocate. Do I need a SAVE atribute to be added to this array?

On a different note, the DLL works the first time it is called. It will run in the debugger when I step through it. When I do not step through it, or when I run it outside the debugger, it crashes. If, within the VB caller, I add a Debug.Print statement upon the return from the subroutine, it again runs. Any idea as to the cause of this behaviour?

0 Kudos
1 Reply
bendel_boy_2007
Beginner
416 Views
Having tested, yes, it does need SAVE. And my crash was caused by an out-by-one array access.
0 Kudos
Reply