Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. from ctypes import string_at
  2. from sys import getsizeof
  3.  
  4. mem_address = 0x7c3f
  5. value = string_at(id(mem_address), getsizeof(mem_address))
  6.  
  7. #include <map>
  8.  
  9. //Somewhere in your program you have a variable
  10. int my_var = 5;
  11.  
  12. //Declare a map of string mapping to 64 bit pointers
  13. std::map<std::string, long long> var_map;
  14.  
  15. //At any point you decide to register the reference of this value
  16. var_map["my_var"] = (long long) &my_var;
  17.  
  18. //Now that you have registered this value,
  19. //you can access it according to the name and
  20. //type cast it as well to a data structure that you like
  21. int *ptr = (int *) var_map["my_var"];
  22.  
  23. //Now you can play around with this:
  24. *ptr = 1024;
  25.  
  26. typedef ReadCommand {
  27. char *var_name;
  28. int read_bytes;
  29. }
  30.  
  31. //Code in program A
  32. ReadCommand read_command;
  33. read_command.var_name = "my_var";
  34. read_command.bytes = 4;
  35.  
  36. try {
  37. //Need to declare message_queue, please see doc in Boost
  38. message_queue_A->send(&read_command, sizeof(ReadCommand), 0);
  39. } catch (boost::interprocess::interprocess_exception &ex){
  40. //Handle exception
  41. }
  42.  
  43. //Best to have struct definition in shared header file
  44. ReadCommand read_command_B;
  45. int some_priority;
  46. boost::interprocess::message_queue::size_type size_of_data_recvd;
  47. message_queue_B->receive(&read_command_B, sizeof(ReadCommand), size_of_data_recvd, some_priority);
  48.  
  49. //use information in read_command_B
  50. //to access var_map then use another
  51. //message queue to send back data to
  52. //Program A which will be expecting
  53. //some information from program B.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement