zoukankan      html  css  js  c++  java
  • boost::interprocess::shared_memory_object(1)(基本类型)

    #include <iostream>
    #include <boost/interprocess/managed_shared_memory.hpp>
    struct pos2d
    {
        int x;
        int y;
    };
    using namespace std;
    int main()
    {
        //boost::interprocess::shared_memory_object类是按照单个字节的方式读写共享内存,用起来不方便
        boost::interprocess::shared_memory_object::remove("Highscore"); 
        boost::interprocess::managed_shared_memory managed_shm(boost::interprocess::open_or_create, "Highscore", 1024);//分配1024字节
        pos2d pos = {1, 1};
        auto ptr = managed_shm.construct<pos2d>("pos2d")(pos); 
        std::pair<pos2d*, std::size_t> p = managed_shm.find<pos2d>("pos2d"); 
        if (p.first) //first是对象的指针,second表示对象的个数
        { 
            std::cout << p.first->x << p.first->y << std::endl; 
            std::cout << p.second << std::endl; 
        }
        getchar();
        return 0;
    }
  • 相关阅读:
    [火柴排队]
    [NOI2001食物链]
    [黑科技]
    [SDOI2009HH的项链]
    [GXOI/GZOI2019旅行者]
    [Nim游戏]
    Log4Net
    C#创建windows服务并定时执行
    MySQL实现类似Oracle的序列
    DevExpress XtraTreeList的复选框 禁用
  • 原文地址:https://www.cnblogs.com/zzyoucan/p/3755988.html
Copyright © 2011-2022 走看看