List, Array and Map parameters can cause issue when exported

Just starting out? Need help? Post your questions and find answers here.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

List, Array and Map parameters can cause issue when exported

Post by luis »

"List, Array and Map parameters can cause issue when exported with ProcedureDLL"

This is a warning from the compiler, at least in 4.50RC2

The procedure is declared as:

Code: Select all

ProcedureDLL .i DummyProcName (Array DummyArray(1)) 
Can anyone please explain what the warning means ?

Has this to do only with the following remark from the manual ?
HELPFILE wrote: - The declaration of arrays, linked lists or map with Dim, NewList or NewMap must always be done inside the procedure AttachProcess
or there is more ?

Is there a problem in declaring an Array() in a PB client program and pass it to a DLL procedure as in the declaration above ?

Thanks.
"Have you tried turning it off and on again ?"
A little PureBasic review
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: List, Array and Map parameters can cause issue when expo

Post by Trond »

From what I can understand, it's related to memory allocation. The dll and the main program have separate string and memory heaps. If you try to resize the array, or reassign strings/map elements in it, things will not be ok. So they are all read-only except for the modification of numeric values. But that's only the theory, I don't know if there any practical issues in the implementation that would make reading troublesome too.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: List, Array and Map parameters can cause issue when expo

Post by Josh »

i think, array, lists and maps are pb-specific. any other programm, not written in pb will have problems with this parameters, when using your dll.
sorry for my bad english
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: List, Array and Map parameters can cause issue when expo

Post by luis »

@trond

I tried to pass back and forth a global array from/to a client/dll and it seem to work ok.

As you wrote, the problem arise if it try to modify the array contents.

I hope this is what the warning from the compiler was about.

If Fred / freak can clarify this beyond any doubt would be nice...

Thanks.

@josh

Yes, I was talking from a PB-only point of view... certainly another language cannot be expected to understand specific PB data structures.
"Have you tried turning it off and on again ?"
A little PureBasic review
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

Re: List, Array and Map parameters can cause issue when expo

Post by TO7 »

I know it's an old thread, but how replace

Code: Select all

ProcedureDLL TheFunction(Array Tablo.DirectoryEntry(1))
and

Code: Select all

ProcedureDLL TheFunction(Array Tablo.s(1))
if obviously, it's not the same thing

Thanks
Sorry but, Google translate is my friend :-(
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: List, Array and Map parameters can cause issue when expo

Post by Little John »

I've got a similar question as luis had about 10 years ago. :-)

PB 5.72 LTS still raises the same compiler warning in this context.

I would like to create a DLL with PB 5.72 that contains a procedure with a linked list as parameter. The main EXE program (also compiled with PB 5.72) should call the procedure in the DLL, that procedure should create elements in the linked list and populate them. Then the main program should read the contens of the linked list.

Something that essentially works like this:

Code: Select all

; PB 5.72 LTS

; ----------------------------------------------
;-- DLL

ProcedureDLL Foo (List myList$())
   ClearList(myList$())
   AddElement(myList$()) : myList$() = "one" 
   AddElement(myList$()) : myList$() = "two" 
   AddElement(myList$()) : myList$() = "three" 
EndProcedure
; ----------------------------------------------


; ----------------------------------------------
;-- Main program

NewList bar$()

Foo(bar$())
ForEach bar$()
   Debug bar$()
Next   
; ----------------------------------------------
Is that possible?

What does the compiler warning
List, Array and Map parameters can cause issue when exported with ProcedureDLL
exactly mean?
luis wrote:If Fred / freak can clarify this beyond any doubt would be nice...
Yes, please. :-)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: List, Array and Map parameters can cause issue when expo

Post by netmaestro »

I suspect the potential issue would appear in the event that a PB coder makes a dll that exports lists arrays or maps and the calling program is not PureBasic. Apart from that I see nothing to worry about.
BERESHEIT
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: List, Array and Map parameters can cause issue when expo

Post by Little John »

Hello netmaestro,

thank you for your answer!
The tests I did went well, but because of the warning I thought I just might have been lucky so far.
That statement from you as someone who has very profound knowledge in computer programming and also specifically with PureBasic gives me more trust.
Many thanks again!
Post Reply