作者Ting1024 (無)
看板C_and_CPP
標題Re: [問題] 在不同process間使用callback function
時間Thu Dec 29 20:07:57 2011
※ 引述《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
推 sawang:感謝Ting1024,小弟對你使用shared memory的解法很有興趣 12/29 20:31
推 x000032001:期待可以在這串看到有趣的東西 12/29 23:27
→ chengcti:用 shared memory 吧, 簡單又不傷效能 12/30 00:22
→ sawang:抱歉問個問題,shared memory除了data之外也可以分享code嗎 12/30 11:46
→ sawang:我看到的範例是將一塊malloc來的空間attach到不同process 12/30 11:47
→ Ting1024:不用刻意想到那方面,DLL函示只要宣告export 12/30 13:46
→ Ting1024:本來就是共享的,每個人都可以去呼叫他... 12/30 13:47
→ Ting1024:只要針對記憶體不同狀態,呼叫對應處理函示即可。 12/30 13:47