Jump to content

_SharedVar (IPC) - Share variables between Autoit and C++/Autoit directly on memory


Recommended Posts

Posted (edited)

Hello,
In recent days I have researched about how to make shared variables

This code is designed to give the ability to:
[Autoit A <-in/out--> Autoit B]
[C++ <--in/out--> Autoit]
[C++ A <--in/out--> C++ B]

 

56de0885d9e76_example1.thumb.png.3ad2517

56de0efcd3e3f_example2.thumb.png.6fa9ca3

56de0f1fa789b_example3.thumb.png.fc87e09

56de0f34a7f5e_example4.thumb.png.74013a1

 

Key points:

  • Share variables between number of processes using the memory (ram). It does not share the information through file (like ini or something like that). it works on pure memory.
  •  Share variables between 1+ Autoit process(s) to to 1+ C++ process(s).
  •  Any process can be master.. but on different variables.. for example Process A can be master for variables X, Y, Z while Process B can be master for variables Q, R, T. (Not showed in the examples).  In C++ version these rules are more flexible.
  • arrays between Autoit and C++ transfer theoretically.
  • You can share as many variables you want.

 

Please note:
You can get race condition bug.
If you share some variable between processes, make sure that when Sub-system-A is changing variable X, Sub-system-B (that running in other process) will not use variable X for calculation..
In this case
you should design the code so only one sub-system will run.. for this you can create shared variable that for
each sub-system that will "say" that this system is run.. so for example Sub-system-B will run only if the variable "say" that Sub-system-A is not running.
I do not know if you understanding .. Probably not. It's hard to explain.

The important thing is - these functions are not designed to handle the "race condition". You need to make sure in your code area that race condition will not happen.
 


Example codes:

 

  Reveal hidden contents

Functions:
Autoit version (v2.3):
_SharedVar_InitializeShare - Initialize/set the way of how the variables that stored inside this process will be shared with other processes.
_SharedVar_SetTargetProcess - Set *target_process (not new process)
_SharedVar_SetNewTargetProcess - Set and add the new *target_process of where to connect the variables during the declaration.
_SharedVar_DeclareVar - Declare the *shared_variable
_sv_write - Write Value in the *shared_variable
_sv_read - Read the *shared_variable
_sv_readlast - Get the last readed value from the *shared_variable.
_SharedVar_CloseProcess - Close the memory handle of the process if memory handle create before.

C++ version (v1.0):
.initialize - initialize for the functions. You must call it once before using any functions in this library!
.share - Share the variable with the other process
.CreateLinker - Create *linker for the variable, return *linker
.UpdateIn(*linker) - Update the *copy_variable to the value of *parallel_variable (Equivalent to _sv_read(*))
.UpdateOut(*linker) - Update the *parallel_variable to the value of *copy_variable (Equivalent to _sv_write(*))
.SetNewTargetProcess - Set and add the new *target_process of where to connect the variables...
.SetTargetProcess - Set *target_process that was added before (not new process)
.StrPtr2IntPtr - Convert [Pointer as string] to [Pointer as int]

Download:

Latest Version (C++ version  and Autoit version)

https://github.com/GilEli1/-Autoit-C-Shared-Vars/releases/tag/1

 

_SharedVar v2.1.rar

* _SharedVar_ReadVar changed to _sv_read
* _SharedVar_WriteValue changed to _sv_write
* Much better example thanks to my _GUIConsole
* Removed old unused code from v1
* Removed unnecessary errors checks
* Fixed bug in _SharedVar_SetDeclarationsInProcess

_SharedVar v2.rar
_SharedVar v1.rar

 

Enjoy ! :)

 

 

Edited by Guest
Posted
  On 2/14/2016 at 10:53 PM, argumentum said:
HotKeySet('{ESC}','Exit1')

won't work for both :( , other than that, nice :) 
What would the max string length be to use ?

Expand  

I know it does not work.
But I spend time on the hard part and I have no time for small things..

About your question -
I did not mention it: If the shared variable may at some point store string value that is bigger then the string that was assigned during the first declaration then you must  to declare the variable bit differently:

In _SharedVar_DeclareVar, in parameter $DataType you need to write the DataType manually.
Try 'char[255]'

Then when you write another string, it will be fine as long as the string smaller then 255 characters.

I have no power today to check it out more. It should work

Posted
  On 2/15/2016 at 11:55 PM, Xandy said:

Hi I just wanted to chime in that I am very interested in this idea and / or any spin off works.  Thank you very much for your pursuit of this goal.

Good luck :)

Expand  

Thanks.
I found a great breakthrough


I will continue to run on it tests on it in the following days when I have free time.
If I see that it works stable enough, I'm probably going to do  separate version of this function which will work much more effectively for Autoit and for the user.

Posted (edited)

Updated again.
I do not like to say this, but I have to:
likes are not enough.

I need comments.

I will now start working on version of this functions for C++ ( _SharedVar.cpp )

Edited by Guest
Posted

Isn't this just a proof of concept and not something that is "production" viable?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)
  On 2/20/2016 at 7:22 PM, guinness said:

Isn't this just a proof of concept and not something that is "production" viable?

Expand  

I did not understand the question.
Can you explain more the question?


What do you mean by saying  ' "production" viable' ?
Edit: I think that I understand but I hope I understand it wrong

Edited by Guest
Posted (edited)

To me production viable means, can it be relied on?  I've been very busy myself working on a multiclient game server and I might have a need of this to speed up sub processes performed by compiled scripts or even C++.  I've been busy but is there something I could help you with?  Maybe you could bring me up to speed with a teamviewer session or workflow videos.  But then that is time you're not doing this and like I said I am busy but you can let me know if that is something you'll want to do.

Edited by Xandy
Posted (edited)

Thanks for your suggestion. :) At the moment I do not need help.

Edited by Guest
Posted (edited)

Thanks for sharing! :thumbsup:

  On 2/20/2016 at 7:17 PM, gil900 said:

I do not like to say this, but I have to:
likes are not enough.
I need comments.

Expand  

Why? What is there to say really? :blink:

It either works or it doesn't, and people either like it or they don't.

To me, it is a thought provoking niche project.

I can see where it can come in handy due to speed and permissions issues over sharing a Registry entry or something like an INI file, but I'm not sure how many exactly have an immediate need for this, or are just like me, storing it away for that day? To make further comment now, you really need to be using it here and now.

And further to all that, I guess it is only useful where you are the author of all the programs that will be sharing the variable(s) ... or have access to the source codes of all ... so that limits things even further.

Don't get me wrong though, I'm glad for your hard work and that you shared this. :D

P.S. In all reality, you are lucky to get a Like, as many offerings here don't even get that or a 'Thank You' despite large numbers of downloads, etc ... and comments are even rarer unless a bug is found or understanding is difficult. :'(

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted (edited)

Thank you,
What I said about the likes..., on second thought I should not say this ..
My approach is changing. I do what I do for fun. I probably would continue to work on this project anyway..Probably in a week from now, I'll  finish to create c++  Version so c++ exe will able to share variables with autoit (using this implemented communication standard)it means that in theory you can for example write all the gui stuff in Autoit and the other in c and it will act like one program. This is my goal and it is fun to build the base for this.

Edited by Guest
Posted (edited)

So I had some free time today and I made small progress:
 

  Reveal hidden contents

 

Edited by Guest
Posted (edited)

Updated: C++ Version released. Autoit version improved

Edited by Guest

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...