且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在两个线程之间共享一个大的高速数据

更新时间:2022-10-24 09:15:27

抱歉,你需要一个全局数据资源。这是避免复制数据的唯一可能性。您必须管理的访问权限,例如使用Mutex。您将找到一个示例这里

Hello, I'm a green hand. Now I meet a puzzle. I need received and then send a char[2048] array continually.
In my mind put receiving and sending in one thread inefficiency . So I create two threads sending and receiving. I have multicore so these two threads could parallel running.
Now my problem is how can I share the char array between two threads. First of all, the global variable shouldn't used. What's way should I choose. Then did the buffer should be used ie page buffer .
Could you give me some advice?

Sorry but you need a global data resource. It is the only possibility to avoid copying data. The access you must manage, for instance with a Mutex. An example you will find here..