#pragma section
看了别人使用了#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的更多相关文章
- 实例详解——编译器命令#pragma section作用于函数时作用域是否覆盖到其子函数
在之前的博客[链接脚本(Linker Script)应用实例(一)使用copy table将函数载入到RAM中运行]中,我们第一步使用#pragma section命令将PFlashProgram函数 ...
- 小侃#pragma
#pragma是一个编译器指令. ================================================================ #pragma comment(li ...
- #pragma init_seg
先进后出原则,最先初始化的最后析构! 1.C++中全局对象.变量的构造函数调用顺序是跟声明有一定关系的,即在同一个文件中先声明的先调用.对于不同文件中的全局对象.变量,它们的构造函数调用顺序是未定义的 ...
- #pragma预处理命令详解
#pragma预处理命令 #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") ...
- #pragma预处理命令【转】
原文 : http://www.cnblogs.com/qinfengxiaoyue/archive/2012/06/05/2535524.html #pragma可以说是C++中最复杂的预处理指令了 ...
- 【VS开发】#pragma预处理命令
#pragma预处理命令 #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") ...
- 深入理解Objective-C:Category
摘要 无论一个类设计的多么完美,在未来的需求演进中,都有可能会碰到一些无法预测的情况.那怎么扩展已有的类呢?一般而言,继承和组合是不错的选择.但是在Objective-C 2.0中,又提供了categ ...
- 搭建基于 STM32 和 rt-thread 的开发平台
我们需要平台 如果说,SharePoint 的价值之一在于提供了几乎开箱即用的 innovation 环境,那么,智能设备的开发平台也一样.不必每次都从头开始,所以需要固定的工作室和开发平台作为创新的 ...
- RFC-2068-http
本文档规定了互联网社区的标准组协议,并需要讨论和建议以便更加完善.请参考 “互联网官方协议标准”(STD 1)来了解本协议的标准化状态.本协议不限流传发布. 版权声明 Copyright (C) Th ...
随机推荐
- phantomjs form提交
phantomjs表单提交,其实就是对DOM就行操作(获取元素),在这里实现了动态传入各种参数 不说了 直接上代码 var page = require('webpage').create(), sy ...
- 关于 addEventListener 和 handleEvent 方法
使用 addEventListener 可以绑定事件,并传入回调函数. Mozilla 0.9.1 和 Netscape 6.1 之后的版本不但支持传递函数引用,也都允许直接把拥有 handleEve ...
- MAC Intellij IDEA 常用快捷键
MAC Intellij IDEA 常用快捷键 Copy by: http://blog.csdn.net/cym492224103/article/details/40077253 Keymap 设 ...
- python之pandas模块
一.pandas模块是基于Numpy模块的,pandas的主要数据结构是Series和DadaFrame,下面引入这样的约定: from pandas import Series,DataFrame ...
- 分治算法求乘方a^b 取余p(divide and conquer)
传统的计算方法为循环n个a相乘.时间复杂度为O(n). 如用分治算法,效率可提升至O(lgn). 结合recursive有 double pow(int a, int n){ ) ; ) return ...
- Core Data (2)-备用
1.Core Data 是数据持久化存储的最佳方式 2.数据最终的存储类型可以是:SQLite数据库,XML,二进制,内存里,或自定义数据类型 在Mac OS X 10.5Leopard及以后的版本中 ...
- Android Development Tools 发生checkAndLoadTargetData错误
之前使用时没有出现任何问题的,我把D:\IDE\ADT\adt-bundle-windows-x86_64-20140321\eclipse目录下面的 eclipse.exe重名名为adt.exe并设 ...
- CSS3----background:-webkit-gradient()渐变效果
input[type="button"], input[type="button"]:visited { background: -webkit-gradien ...
- HDU 2457 DNA repair (AC自动机+DP)
题意:给N个串,一个大串,要求在最小的改变代价下,得到一个不含上述n个串的大串. 思路:dp,f[i][j]代表大串中第i位,AC自动机上第j位的最小代价. #include<algorithm ...
- 一键安装IIS的点点滴滴——For所有Microsoft的操作系统(上)
原文www.cnblogs.com/cdts_change/archive/2010/03/04/1677338.html 临近公司的软件要完工了,最近几天一直在泉哥的带领下为我们公司的产品做IIS一 ...