Beispiel #1
0
void cObserver::SetMemoryID(const String sharedMemoryID)
{
    try
    {
        //Create a shared memory object.
        m_SharedMemoryObject = windows_shared_memory(open_only, sharedMemoryID.c_str(), read_write);

        //Map the whole shared memory in this process
        m_MappedRegion = mapped_region(m_SharedMemoryObject, read_write);

        size_t bufferSize = (m_MappedRegion.get_size() - RESERVE_SIZE)/2;

        //First we'll set the timestamps and key:
        m_ServerTimestamp = (boost::posix_time::ptime *)m_MappedRegion.get_address();
        m_ClientTimestamp = (boost::posix_time::ptime *)m_ServerTimestamp + sizeof(boost::posix_time::ptime);

        m_Key = (Char *)m_ClientTimestamp + sizeof(boost::posix_time::ptime);
        m_BufferSize = (U64 *)(m_Key + sizeof(Char[cEntity::KEY_SIZE_IN_BYTES]));

        //Set the buffer pointers to the two halves of the allocated shared memory.

        //Note that the outbound and inbound bufferes are the opposite of the server!
        //This means that our read buffer is the server's write buffer,
        //and our write buffer is the server's read buffer.
        U8 *outboundBufferAddress = (U8 *)m_BufferSize + sizeof(U64);
        U8 *inboundBufferAddress = outboundBufferAddress + bufferSize;

    }
    catch(interprocess_exception &ex)
    {
        shared_memory_object::remove(sharedMemoryID.c_str());
        std::cout << ex.what() << std::endl;
    }

}
Beispiel #2
0
memmap_reader::memmap_reader(int size) {
    data_size = size;

    //Position
    //Memory Mapping
    file_mapping m_fileX((const char*)config::posX_data_path.string().c_str(),read_only);
    m_regionX = mapped_region(m_fileX, read_only,0,data_size * sizeof(double));
    file_mapping m_fileY((const char*)config::posY_data_path.string().c_str(),read_only);
    m_regionY = mapped_region(m_fileY, read_only,0,data_size * sizeof(double));
    file_mapping m_fileZ((const char*)config::posZ_data_path.string().c_str(),read_only);
    m_regionZ = mapped_region(m_fileZ, read_only,0,data_size * sizeof(double));
    
    //Set Position Data
    posX_data = (double *)m_regionX.get_address();
    posY_data = (double *)m_regionY.get_address();
    posZ_data = (double *)m_regionZ.get_address();
    
    //Size
    //Memory Mapping
    file_mapping m_file2((const char*)config::siz_data_path.string().c_str(),read_only);
    m_region2 = mapped_region(m_file2, read_only,0,data_size * sizeof(double));
    //Set Position Data
    size_data = (double *)m_region2.get_address();
    
    //Rotation
    //Memory Mapping
    file_mapping m_fileP((const char*)config::rotP_data_path.string().c_str(),read_only);
    m_regionP = mapped_region(m_fileP, read_only,0,data_size * sizeof(double));
    //Set Position Data
    rotP_data = (double *)m_regionP.get_address();
    
    file_mapping m_fileQ((const char*)config::rotQ_data_path.string().c_str(),read_only);
    m_regionQ = mapped_region(m_fileQ, read_only,0,data_size * sizeof(double));
    //Set Position Data
    rotQ_data = (double *)m_regionQ.get_address();
    
    file_mapping m_fileR((const char*)config::rotR_data_path.string().c_str(),read_only);
    m_regionR = mapped_region(m_fileR, read_only,0,data_size * sizeof(double));
    //Set Position Data
    rotR_data = (double *)m_regionR.get_address();
}