Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
neurali:shared_memory [2015/08/10 11:29]
profpro
neurali:shared_memory [2015/08/10 11:34]
profpro
Line 18: Line 18:
  
 <code cpp> <code cpp>
-#include <​boost/​interprocess/​shared_memory_object.hpp>​ +  ​#include <​boost/​interprocess/​shared_memory_object.hpp>​ 
-using boost::​interprocess;​ +  using boost::​interprocess;​ 
- // la creazione potrebbe lanciare eccezione se già esiste +   ​// la creazione potrebbe lanciare eccezione se già esiste 
-shared_memory_object shm_obj(create_only,"​shared_memory",​read_write);​ +  shared_memory_object shm_obj(create_only,"​shared_memory",​read_write);​ 
-shm_obj.truncate(1000);​ // dimensione della memoria condivisa +  shm_obj.truncate(1000);​ // dimensione della memoria condivisa
- +
-shared_memory_object shm_obj(open_only,"​shared_memory",​read_only);​ +
- +
 </​code>​ </​code>​
  
  
 <code cpp> <code cpp>
-#include <​boost/​interprocess/​mapped_region.hpp>​ +  ​#include <​boost/​interprocess/​mapped_region.hpp>​ 
-#include <​iostream>​ +  #include <​iostream>​ 
-#include <​cstring>​+  #include <​cstring>​
  
-std::size_t ShmSize = 1000;+  ​std::size_t ShmSize = 1000;
  
-mapped_region region+  ​mapped_region region
    ( shm_obj ​                 //​Memory-mappable object    ( shm_obj ​                 //​Memory-mappable object
    , read_write ​              //​Access mode    , read_write ​              //​Access mode
Line 44: Line 40:
    );    );
        
-std::​memset(region.get_address(),​ 0, region.get_size());​+  ​std::​memset(region.get_address(),​ 0, region.get_size());​ 
 +</​code>​
  
  
 +<code cpp>
 +  // la rimozione potrebbe lanciare eccezione se memoria in uso da altri
 +  shared_memory_object::​remove("​shared_memory"​);​
 </​code>​ </​code>​
  
- +Altro accesso alla memoria precedentemente condivisa
- +
  
 <code cpp> <code cpp>
-// la rimozione potrebbe lanciare eccezione se memoria in uso da altri +  ​shared_memory_object ​shm_obj(open_only,"​shared_memory"​,​read_only);​ 
- +  const char *p = static_cast<​char*>​(region.get_address());
-shared_memory_object::remove("​shared_memory"​);​+
 </​code>​ </​code>​
  • neurali/shared_memory.txt
  • Last modified: 2018/04/25 07:55
  • (external edit)