Re: Pointers and DLLs/shared libraries
- From: Craig Powers <enigma@xxxxxxxxxx>
- Date: Mon, 26 Nov 2007 17:18:45 -0500
Arjen Markus wrote:
Hello,
I have a module residing in a DLL or shared library (I need to support
both
Windows and Linux here) and this module contains a number of pointer
variables.
These pointer variables will point to data in the main program. To
illustrate:
module my_pointers
real, dimension(:), pointer :: p
contains
subroutine set_pointer( data )
real, dimension(:), target :: data
p => data
end subroutine
subroutine use_pointer( x )
p = p + x
end subroutine
end module
program test_pointers
real, dimension(:), pointer :: data
allocate( data(1:100) ) ! Allocate the array: it is a pointer too
in the actual program
call set_pointer( data )
call use_pointer( 10.0 )
end program
(Of course, I have a multitude of such pointers in the module,
which is the main reason to use this set-up).
My question is:
Is it safe to do something like this? Are the pointers valid?
(DLLs and shared libraries do not always behave like ordinary
libraries)
I can't speak for the Linux side of things, but in Windows...
....the DLL effectively becomes a part of all of the client programs that use it. On the one hand, that means that you should be able to use pointers where the pointer is in the dll and the data is in the main program, or vice versa (and you should be able to double-check with your compiler documentation). On the other hand, that also means that you have to watch for issues arising when multiple instances of the program are all running on one copy of the dll. Furthermore, you have to watch out for instances where the variables in the dll do not reset, and provide mechanisms for doing so manually.
.
- Follow-Ups:
- Re: Pointers and DLLs/shared libraries
- From: Steve Lionel
- Re: Pointers and DLLs/shared libraries
- From: Arjen Markus
- Re: Pointers and DLLs/shared libraries
- References:
- Pointers and DLLs/shared libraries
- From: Arjen Markus
- Pointers and DLLs/shared libraries
- Prev by Date: Re: Backslashes
- Next by Date: Re: allocating arrays, trouble
- Previous by thread: Pointers and DLLs/shared libraries
- Next by thread: Re: Pointers and DLLs/shared libraries
- Index(es):
Relevant Pages
|
Loading