Re: [問題] 在不同process間使用callback function

看板C_and_CPP (C/C++)作者 (無)時間14年前 (2011/12/29 20:08), 編輯推噓2(206)
留言8則, 4人參與, 最新討論串3/3 (看更多)
※ 引述《chengcti (卡馬請出來面對!!)》之銘言: : 1. IPC / mailslot, pipe, message. : not easy : 2. file share (a simple method) : A, B always check a file every n secs. : When C writes a flag to file. : The A & B read it, and call his function. I recommand the original author to use dll shared memory. It doesn't get the drawback of frequently file I/O as you described above. Shared memory can be mapped to a different address in each process. For this reason, each process has its own instance of memory pointer, which is declared as a global variable so that it is available to all DLL functions. You can integrate the memory content and callback funcitons together, to achieve your purpose. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.141.39.249

12/29 20:31, , 1F
感謝Ting1024,小弟對你使用shared memory的解法很有興趣
12/29 20:31, 1F

12/29 23:27, , 2F
期待可以在這串看到有趣的東西
12/29 23:27, 2F

12/30 00:22, , 3F
用 shared memory 吧, 簡單又不傷效能
12/30 00:22, 3F

12/30 11:46, , 4F
抱歉問個問題,shared memory除了data之外也可以分享code嗎
12/30 11:46, 4F

12/30 11:47, , 5F
我看到的範例是將一塊malloc來的空間attach到不同process
12/30 11:47, 5F

12/30 13:46, , 6F
不用刻意想到那方面,DLL函示只要宣告export
12/30 13:46, 6F

12/30 13:47, , 7F
本來就是共享的,每個人都可以去呼叫他...
12/30 13:47, 7F

12/30 13:47, , 8F
只要針對記憶體不同狀態,呼叫對應處理函示即可。
12/30 13:47, 8F
文章代碼(AID): #1E_5WWNp (C_and_CPP)
文章代碼(AID): #1E_5WWNp (C_and_CPP)