Windows共享記憶體

2021-06-15 09:13:51 字數 1136 閱讀 1624

windows共享記憶體可以讓兩個程序對同一塊記憶體進行讀寫。

//

a.cpp

#include #include

#include

#include

#include

using

namespace

std;

#define buf_size 256tchar szname=text("

"); //

指向同一塊共享記憶體的名字

int main(int argc, char *argv)

pbuf = (lptstr) mapviewoffile(hmapfile, //

handle to map object

file_map_all_access, //

read/write permission0,

0,buf_size);

if (pbuf ==null)

//

//以下**,a不停地讀共享記憶體pbuf

while(1

)

unmapviewoffile(pbuf);

closehandle(hmapfile);

return0;

}

//

b.cpp

#include #include

#include

using

namespace

std;

#define buf_size 256tchar szname=text("

"); //

指向同一塊共享記憶體的名字

intmain()

pbuf = (lptstr) mapviewoffile(hmapfile, //

handle to map object

file_map_all_access, //

read/write permission0,

0,buf_size);

if (pbuf ==null)

//

//以下**,b不停寫共享記憶體pbuf

while(1

)

}

Windows共享記憶體示例

windows共享記憶體可以讓兩個程序對同一塊記憶體進行讀寫。a.cpp include include include include include using namespace std define buf size 256tchar szname text 指向同一塊共享記憶體的名字 in...

Windows共享記憶體示例

windows共享記憶體示例 共享記憶體主要是通過對映機制實現的。下面舉例說明如何將記憶體對映檔案用於共享記憶體。第一次執行這個例子時,它建立了共享記憶體,並寫入資料 this is common data 只要建立共享記憶體 的程序沒有關閉控制代碼hmap,以後執行的程式就會讀出共享記憶體裡面的資...

Windows共享記憶體解析

在windows程式開發過程中,當多個程序之間需要使用同樣的資料的時候我們最好的方式就是通過共享記憶體進行處理 比如 當a程序執行時,進行資料處理,那麼此時我想知道資料是不是正確,用b監控,那麼a與b之間就可以使用共享記憶體的方式,並且這時來個c程序,他也可以訪問這塊共享記憶體資料進行監控 1.共享...