#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[100];

如上定义两个变量,编译完成后,启动两个实例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.
时间: 2024-10-10 19:57:00

#pragma section的相关文章

#pragma预处理命令

#pragma预处理命令 #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") 表示链接XXX.lib这个库,和在工程设置里写上XXX.lib的效果一样. #pragma comment(linker,"/ENTRY:main_function") 表示指定链接器选项/ENTRY:main_function #pragma once 表示这个文件只被包含一次 #pra

#pragma预处理命令【转】

原文 : http://www.cnblogs.com/qinfengxiaoyue/archive/2012/06/05/2535524.html #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") 表示链接XXX.lib这个库,和在工程设置里写上XXX.lib的效果一样. #pragma comment(linker,"/ENTRY:main_function"

#pragma预处理命令详解

#pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") 表示链接XXX.lib这个库,和在工程设置里写上XXX.lib的效果一样. #pragma comment(linker,"/ENTRY:main_function") 表示指定链接器选项/ENTRY:main_function #pragma once 表示这个文件只被包含一次 #pragma warning(d

HTTP1.1协议中文版-RFC2616

转自:http://www.cnpaf.net/Class/HTTP/200811/23277.html 说明 本文档规定了互联网社区的标准组协议,并需要讨论和建议以便更加完善.请参考 “互联网官方协议标准”(STD 1)来了解本协议的标准化状态.本协议不限流传发布. 版权声明 Copyright (C) The Internet Society (1999).   All Rights Reserved. 摘要 超文本传输协议(HTTP)是一种为分布式,合作式,超媒体信息系统.它是一种通用的,

c++中__declspec用法总结

“__declspec”是Microsoft c++中专用的关键字,它配合着一些属性可以对标准C++进行扩充.这些属性有:align.allocate.deprecated. dllexport.dllimport. naked.noinline.noreturn.nothrow.novtable.selectany.thread.property和uuid. 1,_declspec(1)用法一定义接口 #include <IOSTREAM>using namespace std;#defin

深入理解Objective-C:Category

摘要 无论一个类设计的多么完美,在未来的需求演进中,都有可能会碰到一些无法预测的情况.那怎么扩展已有的类呢?一般而言,继承和组合是不错的选择.但是在Objective-C 2.0中,又提供了category这个语言特性,可以动态地为已有类添加新行为.如今category已经遍布于Objective-C代码的各个角落,从Apple官方的framework到各个开源框架,从功能繁复的大型APP到简单的应用,catagory无处不在.本文对category做了比较全面的整理,希望对读者有所裨益. 简介

STM8的数据@near @tiny定义

总是记不住这个:stm8 stvd下 near等于51的xdata tiny等于51的idata http://www.waveshare.net/article/STM8-3-1-10.htm 如何分配变量到指定的地址 举例:unsigned char [email protected]; //定义无符号变量temp_A,强制其地址为0x00unsigned char [email protected]; //定义无符号变量temp_B,强制其地址为0x100@tiny unsigned ch

HTTP和WebSocket协议

websocket是一个新的基于TCP的应用层协议,只需要一次连接,以后的数据不需要重新建立连接,可以直接发送,它是基于TCP的,属于和HTTP相同的地位, 通过消息的方式触发. HTTP HTTP的地址格式如下: http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]] 协议和host不分大小写 HTTP消息 一个HTTP消息可能是request或

IAR EWARM __iar_program_start, __iar_data_init3, __iar_copy_init3, __iar_zero_init3

#include <stdint.h> // The type of a pointer into the init table. typedef void const * table_ptr_t; // The type of an initialization routine. It takes a pointer to the start of // its entry (after the function pointer) in the init table and returns