Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 2 Jahren, 7 Monaten
Letzter Beitrag:
vor 2 Jahren, 7 Monaten
Beteiligte Autoren:
Andrew MacKenzie, Fabrice Harari, Steve Hodgman

How to make variable persist beyond procedure?

Startbeitrag von Andrew MacKenzie am 29.05.2015 18:00

Hi, all!

I'm working on some multi-threading stuff. What I want to happen is for the thread to post messages to its creator's handle (handle passed as parameter to thread procedure). This is easy enough.

However, for the next-level stuff, I want to pass arguments with those messages. Those arguments could be a string, a structure, anything, really. I understand that wParam and lParam are supposed to be integers, but I could pass the address to the memory space. So far so good.

BUT - sometimes my window won't process those messages because the user has the window working on something else. By the time the window gets the message from the thread, the memory is no longer accessible/valid.

So, my question - how can I prevent WinDev from destroying my strings/structures at the end of procedures? I understand that I will have to destroy them in my message handler.


Hi Andrew

I can see several ways of achieving that...

create a dynamic array in the calling program
write in it in the secondary thread
send a message to whatever you want to let them know that there is something in the array it can be strings or anything else)
delete the strings there

create a class with all the possible variables you may need inside (call it message, by example)
before starting your secondary thread, instantiate a dynamic object of that class (or several if necessary) and give its address to the thread
the thread uses the object to store your data, then send a message
the main process receives the message with the dynamic object address (or it remembers it), use the data, and kill the objecyt

You could use the sharedmemory functions


Best regards

von Fabrice Harari - am 29.05.2015 18:10
I was hoping for less work-around, more how-to-caus-a-variable-reference-to-not-be-deleted.

I tried the shared memory first a while back, didn't meet our needs.

Tried the dynamic array which again works as long as there is only one extra thread. Once there's two threads going you start to lose the performance boost of having multiple threads -- semaphores waiting for the array to be available for writing/reading... sucks to my assmar.

I got the same issue with using a class.

Basically, my requirement is that the main thread does not hold reference to any collection of pointers, or use global variables; I need only for the object reference found in the memory address/es of the wParam/lParam arguments of an event to be accessible for comparing (and possibly copying) then for me to free up that memory.

I've got a fully working example in c++, but the requirement is to use WinDev and WinDev language (can't port the dll).

Is this possible in WinDev - yes or no?

von Andrew MacKenzie - am 29.05.2015 19:48
Have you thought of using Queues?
They can be queues of any type of variable. Complex or not.
The queue would need to be declared in the project but multiple threads can read/write to queues "simultaneously". i.e. they are inherently thread safe.
Not sure of your exact requirements but I found they solve my messaging/parameter passing problems.
Steve H.

von Steve Hodgman - am 30.05.2015 07:45
Hi Andrew,

what you are describing matches exactly the class method... one thread=one object... and you can pass back and forth the address/pointer of that object

Best regards

von Fabrice Harari - am 30.05.2015 11:19
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.