首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

程序中产生的数组怎么映射到共享内存中

2012-08-22 
程序中产生的数组如何映射到共享内存中?通过CreateFile()CreateFileMapping() MapViewOfFile()的方法应该

程序中产生的数组如何映射到共享内存中?

通过CreateFile()CreateFileMapping() MapViewOfFile()的方法应该是将存放在磁盘上的文件映射到共享内存,我需要将程序中产生的一个数组存放到共享内存区,让另一个进程来共享这个数组,请问这种情况应该使用那些函数呢? 或者可不可以让我产生的这个数组直接放置到共享内存区,这样可以节省一些内存。请大家指点一下,多谢了!!

[解决办法]
貌似只有ring0级别的内存是共享。 R3级别 有提供共享内存的函数吗?

[解决办法]
在MSDN里面搜“Using Shared Memory in a Dynamic-Link Library”?

README.TXT
How to Share Memory Between Processes. SUMMARY ======= The MEMORY sample demonstrates the use of the file mapping functions to create named shared memory. MORE INFORMATION ================ This sample consists of a client and a server. Server ------ The server sets up the named share memory. A server can be created by selecting Server from the Create menu. This opens up a MDI child and swaps the menu bar to the server menu bar. To set up the equivalent of a named shared memory: - Select Create File from the Server menu. This brings up the File Type dialog box. The user may create either a memory page file or a physical file by clicking on the Page File or the Map File button respectively to back up the soon-to-be-created named shared memory. If the Map File button is selected, the named shared memory will be backed up by a physical file on the disk. On the other hand, if the Page File button is clicked, the memory will be backed up by the memory page file. - Select Create File Mapping from the Server menu. This brings up the Map Name dialog box. The user then specifies a name for the file-mapping object which will be created for the file created in step 1 above. This name will be used to identify the shared memory by the clients in the other processes. - Select Map View of File from the Server menu. This maps the file-mapping object created in the step above into the process virtual address space. - Select Access from the Server menu. This creates a MLE inside the MDI Server child. Whatever was written in the MLE is put in the map file object. Client ------ The client connects to the named shared memory created by the server process. A client can be created by selecting Client from the Create menu. This opens up an MDI child and swaps the menu bar to the client menu bar. To set up the connection to the named share memory: - Select Open File Mapping from the Client menu. This brings up the Map Name dialog box. The user can then enter the name of the file-mapping object which the client wanted to connect to. - Select Map View of File from the Client menu. This maps the file-mapping object opened in the step above into the process virtual address space. - Select Access from the Client menu. This creates a MLE inside the MDI Server child. Whatever was written in the file-mapping object by the server will be shown in this MLE. The client synchronizes with the server at regular intervals. - Select Refresh Now from the Client menu to refresh the contents of the file-mapping object immediately. 
 


[解决办法]
参考C:\MSVC20\SAMPLES\win32\memory\*.*
VC++2.0 MSVC20 "Microsoft Visual C++ Version 2.0" "1994 Microsoft Corporation" 
http://download.csdn.net/detail/zhao4zhong1/3253384

热点排行
Bad Request.