- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Jeremy
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page