Saving an ALLOCATABLE array

Saving an ALLOCATABLE array

I was hoping to allocate an array in a dll and pass it back to the calling VB code. From browsing the docs, a locally allocated array is deallocated when the sub/func is exited, either by default or by DEALLOCATE. The SAVE attribute conflicts with the ALLOCATABLE attribute.

It appears that I cannot do what I want. Is this true, or have I missed something?

My work around is to write another function to determine the size, dimension it in VB and pass the first element of the array and its dimension.

Thanks for any remarks.
Ted

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

SAVE attribute does not conflict with ALLOCATABLE. It's perfectly OK and standard to declare an array ALLOCATABLE,SAVE. The problem might be if VB unloads your dll in the meantime -- I don't think it does it, so you might give it a try.

However, (out of curiosity, I'm not familiar with VB), how do you mean to "pass it" to VB code? That implies that VB is able to dereference it via a C-style pointer -- I don't recall if it can do it (note that even standard Fortran-95 cannot have ALLOCATABLE arguments). OTOH, that method would require separate routines (or additional argument in the call) to allocate/deallocate arrays.

...I must admit I like your "workaround" more -- that interface is cleaner.

Jugoslav

Jugoslav
www.xeffort.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today