Pass an array from one Gambas program to another?
Posted: Saturday 21st September 2019 8:04am
I've written a Gambas program that does four CPU-intensive tasks in sequence. One task can't begin until the previous one ends, etc.
Everything works well. But from start of the first task, till the end of the last task, takes about 2 minutes. I've considered buying a new computer with a cutting-edge processor that could do the same sequence of tasks in a fraction of the time.
But here's the thing. The computer I'm now using has a 4-core CPU. While these CPU-intensive tasks are being carried out, the CPU usage on one core remains at 100% while the others remain essentially idle. The overall CPU usage, of course, never goes above 25%, because each Gambas program only uses one thread.
It occurred to me that I could avoid having to buy a new computer if I could better utilize this CPU.
If I could create several "slave" programs, and communicate an array, or at least a huge block of text that can be Split() into an array by each slave, then all four CPU cores could be utilized at once. Done in parallel, the same work could in theory be done in 30 seconds.. Once finished, each slave could communicate its resulting arrays, or huge blocks of text, back to the main program in the same manner.
In my VB6 days, this kind of thing could be done fairly easily. I could find a slave program's hWnd with the FindWindow API call, find its child textbox hWnd with a nifty function FindChildObjectByClass. Then use
The slave could then Split() that text into an array, perform a task with it, and then send the result back to the main program's textbox in the same manner.
Does anyone know if Gambas can send arrays, or at least hugs blocks of text, between separate running programs?
If not, a workaround that should provide the same functionality would be to use the clipboard. But it would mean the clipboard would always be tied up and unusable, with data always being bounced around back and fourth in it. If I were to mindlessly copy something to the clipboard while these programs are operating, chaos could ensue. So I'd rather avoid using the clipboard if I can. But it may be my best option.
Anyways, thanks for reading. Keep on Gambasing.
Everything works well. But from start of the first task, till the end of the last task, takes about 2 minutes. I've considered buying a new computer with a cutting-edge processor that could do the same sequence of tasks in a fraction of the time.
But here's the thing. The computer I'm now using has a 4-core CPU. While these CPU-intensive tasks are being carried out, the CPU usage on one core remains at 100% while the others remain essentially idle. The overall CPU usage, of course, never goes above 25%, because each Gambas program only uses one thread.
It occurred to me that I could avoid having to buy a new computer if I could better utilize this CPU.
If I could create several "slave" programs, and communicate an array, or at least a huge block of text that can be Split() into an array by each slave, then all four CPU cores could be utilized at once. Done in parallel, the same work could in theory be done in 30 seconds.. Once finished, each slave could communicate its resulting arrays, or huge blocks of text, back to the main program in the same manner.
In my VB6 days, this kind of thing could be done fairly easily. I could find a slave program's hWnd with the FindWindow API call, find its child textbox hWnd with a nifty function FindChildObjectByClass. Then use
Code: Select all
Call SendMessageByString(ChildhWnd, WM_SETTEXT, 0, "This is the text to be sent.")
Does anyone know if Gambas can send arrays, or at least hugs blocks of text, between separate running programs?
If not, a workaround that should provide the same functionality would be to use the clipboard. But it would mean the clipboard would always be tied up and unusable, with data always being bounced around back and fourth in it. If I were to mindlessly copy something to the clipboard while these programs are operating, chaos could ensue. So I'd rather avoid using the clipboard if I can. But it may be my best option.
Anyways, thanks for reading. Keep on Gambasing.