#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 ...
随机推荐
- 【Nutch2.2.1源代码分析之4】Nutch加载配置文件的方法
小结: (1)在nutch中,一般通过ToolRunner来运行hadoop job,此方法可以方便的通过ToolRunner.run(Configuration conf,Tool tool,Str ...
- 插件的理解$.extend()与$.fn.extend()
插件的理解.$.extend()与$.fn.extend() 插件开发包括两种:1.类级别的插件开发,即$.extend()扩展jquery对象本身:2.对象级别的插件开发,即$.fn.exte ...
- HTML5简介、视频
HTML5 建立的一些规则: 新特性应该基于 HTML.CSS.DOM 以及 JavaScript. 减少对外部插件的需求(比如 Flash) 更优秀的错误处理 更多取代脚本的标记 HTML5 应该独 ...
- linux服务器wget无法成功解析域名及程序获取外网数据不稳定问题
1.问题描述: 1.1 最近发现通过linux服务器wget下载远程文件经常提示无法解析域名问题,要重复多次才能成功,成功率比较低. 1.2 PHP用file_get_contents()函数获取淘宝 ...
- sudo 无法解析主机的解决办法
错误存在于更改主机名字后,解决办法如下: sudo gedit /etc/hosts找到如下行:127.0.1.1 XXX将其修改为:127.0.1.1 (你现在的主机名) 保 ...
- AI自动寻路
1.首先把游戏场景中的物体设为静态 2.选中Window 中的Navigation ,点击Bake进行场景烘焙 3.在需要寻路的游戏对象上添加 NavMeshAgent组件.调整其AgentSize大 ...
- str_翻转字符串
1. 给一个句子,翻转每个单词,单词内部不翻转 $str = "dog loves pig"; $ret = turnSentence($str); var_dump($ret); ...
- C语言生产随机数的方法
尽管在计算机中并没有一个真正的随机数发生器,但是可以做到使产生的数字的重复率很低,以至于它们看起来是随机的.实现这一功能的程序叫做伪随机数发生器. 有关如何产生随机数的理论有许多,这里不讨论这些理论及 ...
- Oracle查看表空间及修改数据文件大小
Oracle查看表空间及修改数据文件大小 第一步:查看所有表空间及表空间大小: select tablespace_name ,sum(bytes) / 1024 / 1024 as MB from ...
- Codeforces 463D Gargari and Permutations
http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...