看了别人使用了#pragma section来共享变量,今天试了下

如下添加代码

#define GLOBAL_SHARED __declspec(allocate(".Shared"))
#pragma section(".Shared",read,write,shared)
GLOBAL_SHARED int gs_nTest;
GLOBAL_SHARED char gs_caTest[];

如上定义两个变量,编译完成后,启动两个实例A和B

在A中进行赋值,可以在B中直接读到,同样在B中赋值,在A中也可以读到,很方便

另外,实验发现:

1、CString变量不可以

2、实例A和B必须是同一程序,路径不同也不可以

网上找的参考

#pragma section( "section-name" [, attributes] )
Creates a section in an .obj file. Once a section is defined, it remains valid for the remainder of the compilation. However, you must use __declspec(allocate) or nothing will be placed in the section. section-name is a required parameter that will be the name of the section. The name must not conflict with any standard section names. See /SECTION for a list of names you should not use when creating a section. attributes is an optional parameter consisting of one or more comma-separated attributes that you want to assign to the section. Possible attributes are: read
Allows read operations on data.
write
Allows write operations on data.
execute
Allows code to be executed.
shared
Shares the section among all processes that load the image.
nopage
Marks the section as not pageable; useful for Win32 device drivers.
nocache
Marks the section as not cacheable; useful for Win32 device drivers.
discard
Marks the section as discardable; useful for Win32 device drivers.
remove
Marks the section as not memory-resident; virtual device drivers (VxD) only.
If you do not specify attributes, the section will have read and write attributes. Example
In the following example, the first instruction identifies the section and its attributes. The integer j is not put into mysec because it was not declared with __declspec(allocate); j goes into the data section. The integer i does go into mysec as a result of its __declspec(allocate) storage-class attribute.

#pragma section的更多相关文章

  1. 实例详解——编译器命令#pragma section作用于函数时作用域是否覆盖到其子函数

    在之前的博客[链接脚本(Linker Script)应用实例(一)使用copy table将函数载入到RAM中运行]中,我们第一步使用#pragma section命令将PFlashProgram函数 ...

  2. 小侃#pragma

    #pragma是一个编译器指令. ================================================================ #pragma comment(li ...

  3. #pragma init_seg

    先进后出原则,最先初始化的最后析构! 1.C++中全局对象.变量的构造函数调用顺序是跟声明有一定关系的,即在同一个文件中先声明的先调用.对于不同文件中的全局对象.变量,它们的构造函数调用顺序是未定义的 ...

  4. #pragma预处理命令详解

    #pragma预处理命令 #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") ...

  5. #pragma预处理命令【转】

    原文 : http://www.cnblogs.com/qinfengxiaoyue/archive/2012/06/05/2535524.html #pragma可以说是C++中最复杂的预处理指令了 ...

  6. 【VS开发】#pragma预处理命令

    #pragma预处理命令 #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") ...

  7. 深入理解Objective-C:Category

    摘要 无论一个类设计的多么完美,在未来的需求演进中,都有可能会碰到一些无法预测的情况.那怎么扩展已有的类呢?一般而言,继承和组合是不错的选择.但是在Objective-C 2.0中,又提供了categ ...

  8. 搭建基于 STM32 和 rt-thread 的开发平台

    我们需要平台 如果说,SharePoint 的价值之一在于提供了几乎开箱即用的 innovation 环境,那么,智能设备的开发平台也一样.不必每次都从头开始,所以需要固定的工作室和开发平台作为创新的 ...

  9. RFC-2068-http

    本文档规定了互联网社区的标准组协议,并需要讨论和建议以便更加完善.请参考 “互联网官方协议标准”(STD 1)来了解本协议的标准化状态.本协议不限流传发布. 版权声明 Copyright (C) Th ...

随机推荐

  1. Linux Shell 中的反引号,单引号,双引号

    反引号在 (`) 键盘的Tab键的上方.1键的左方.在Linux中起着命令替换的作用.命令替换是指shell能够将一个命令的标准输出插在一个命令行中任何位置.如下,shell会执行反引号中的date命 ...

  2. PHP连接Microsoft SQL Server 2005/2008

    PHP自带的MSSQL扩展php_mssql.dll原来是给SQL Server 2000用的,难怪连接不上2008?! -_-!!要使用SQL Server 2005以上版本,就要用到微软为PHP提 ...

  3. 2014-06-13 jq chart

    昨天接到上级说要在检测服务器上增加一个可以根据时间来查看服务器信息的线形图,那我首先就在原有的发送监控信息的功能上增加了把信息存入数据库中,然后再数据库中取得数据显示. 至于线形图的插件是jqx 的c ...

  4. Struts2中的get、set方法作用:

    Struts2中的get.set方法作用: 在Struts2中,客户端和服务器之间的数据传输全部要用到get.set方法:用set方法 ,可以将表单中的值存入Action类.通过Struts2.0标签 ...

  5. FTP两种工作模式:主动模式(Active FTP)和被动模式(Passive FTP)

    在主动模式下,FTP客户端随机开启一个大于1024的端口N向服务器的21号端口发起连接,然后开放N+1号端口进行监听,并向服务器发出PORT N+1命令.服务器接收到命令后,会用其本地的FTP数据端口 ...

  6. CSU 1120 病毒

    最长公共上升子序列(LCIS) 裸的算法题. 动态规划: 两组数组a[n].b[m]. f[i][i]表示以a[i].b[j]结尾的两个数组的LCIS. 转移方程: a[i]!=b[j] : f[i] ...

  7. 正式学习react(二)

    今天把上一篇还没学习完的 webpack部分学习完: 之前有说过关于css的webpack使用.我们讲了 ExtractTextPlugin 来单独管理css讲了module.loaders下关于 c ...

  8. Spring Data JPA之Hello World

    Spring Data Jpa 配置 使用 Spring Data JPA 进行持久层开发需要的四个步骤: 1.配置 Spring 整合 JPA 2.在 Spring 配置文件中配置 Spring D ...

  9. 现有C2B模式小总结

    现有的C2B模式 目前常见的C2B模式有: l  聚合需求形式(反向团购.预售等) l  要约形式(逆向拍卖,客户出价,商家选择是否接受等) l  服务认领形式(企业发布所需服务,个人认领,类似威客等 ...

  10. 感知机(perceptron)

    二类分类的线性分类模型,属于判别模型,利用梯度下降法对损失函数进行极小化求得感知机模型分为原始形式和对偶形式,是神经网络和支持向量机的基础 由输入控件到输出控件的如下函数: f(x)=sign(W.X ...