Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ctypes import string_at
- from sys import getsizeof
- mem_address = 0x7c3f
- value = string_at(id(mem_address), getsizeof(mem_address))
- #include <map>
- //Somewhere in your program you have a variable
- int my_var = 5;
- //Declare a map of string mapping to 64 bit pointers
- std::map<std::string, long long> var_map;
- //At any point you decide to register the reference of this value
- var_map["my_var"] = (long long) &my_var;
- //Now that you have registered this value,
- //you can access it according to the name and
- //type cast it as well to a data structure that you like
- int *ptr = (int *) var_map["my_var"];
- //Now you can play around with this:
- *ptr = 1024;
- typedef ReadCommand {
- char *var_name;
- int read_bytes;
- }
- //Code in program A
- ReadCommand read_command;
- read_command.var_name = "my_var";
- read_command.bytes = 4;
- try {
- //Need to declare message_queue, please see doc in Boost
- message_queue_A->send(&read_command, sizeof(ReadCommand), 0);
- } catch (boost::interprocess::interprocess_exception &ex){
- //Handle exception
- }
- //Best to have struct definition in shared header file
- ReadCommand read_command_B;
- int some_priority;
- boost::interprocess::message_queue::size_type size_of_data_recvd;
- message_queue_B->receive(&read_command_B, sizeof(ReadCommand), size_of_data_recvd, some_priority);
- //use information in read_command_B
- //to access var_map then use another
- //message queue to send back data to
- //Program A which will be expecting
- //some information from program B.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement