Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
14 Views

Copying of structures

Hi, I am using legacy fortran code and it seems that TYPE structures are copied in many places using the scheme struct1=struct2. Then pointers are deallocated from struct1 (which are really pointers or copies of pointers of struct2). My question is, is struct1 copied I would think it is just pointed to struct2. This scheme has worked for many years but when calling the fortran dll from c#, i many times seems to get a Attempted to Read or Write Protected Memory error. Any help or advice is appreciated.
Jeremy
0 Kudos
2 Replies
Highlighted
Beginner
14 Views

Maybe this isnt the best explanation so i'll include the code:

module display
use picturedata
type (picture), SAVE :: pic(50), pictemp
...
end module display

module picturedata
use bitmaptypes
type picture
integer nx,ny
real*4,pointer :: array(:,:)=>Null()
...
end

Then, the project will use display. Creating pic(2)%array, pic(2)%nx ... and calling pic(1)=pic(2), this seems to copy the structure to pic(1) and then pic(1)%array is deallocated and allocated. This seems to work with the legacy code, but when calling from c# i get the accessing proctected memory.
0 Kudos
Highlighted
14 Views

Yes, this looks like a shallow copy is done when a deep copy should be performed.

In the debugger, can you verify the addresses in the pic1 struct, validate what is copied into the pic2 struct, and see what addresses the c# code is seeing and faulting on?

Philip Taylor
0 Kudos