Re: Pointers and DLLs/shared libraries



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.
.



Relevant Pages

  • Pointers and DLLs/shared libraries
    ... I have a module residing in a DLL or shared library (I need to support ... These pointer variables will point to data in the main program. ... subroutine set_pointer ... (DLLs and shared libraries do not always behave like ordinary ...
    (comp.lang.fortran)
  • Re: Importing a Class define in a Dll
    ... pointer as an extra parameter passed to each non-static ... It is specially useful for the ARM platform as the ... MyClass() {... ... Build the DLL containing your class in the same ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Exception handling for loading of dependency library?
    ... typedef int (const CString & s, ... A common technique for doing this is to declare it as a global variable, ... the handle for a given dll all in one place. ... pointless because ANSI C does not require dereferencing function pointer variables. ...
    (microsoft.public.vc.mfc)
  • Re: How to program plugin DLLs
    ... build the descriptor you mentioned. ... That class is the "only" element to be exported from the DLL. ... pointer to that class and then call something like this: ... > What I might consider here is a method which fills in a popup menu. ...
    (microsoft.public.vc.mfc)
  • Re: dll load address
    ... Marco Ventanas ... >> I'm trying to read the dll import table using a pointer initialized to ... >> but as I read the first byte pointed by this pointer, ... but the displayed Base Addr is the same for all ...
    (microsoft.public.windowsce.platbuilder)

Loading