Frequency limit of writing to shared memory?

2019-06-06 10:59发布

Single threaded application (C++) continuously locks, writes and unlocks shared memory - four times a second (the loop is programically set to run once a second and there are 4 writes in the loop and no reads).

EnterCriticalSection(cs);
WriteToSharedMem();
LeaveCriticalSection(cs);

Another application (C) will access this shared memory once every few minutes.

Are there any problems with writing to shared memory at this rate?

Windows XP
C++

3条回答
Deceive 欺骗
2楼-- · 2019-06-06 11:24

Not at all. You can get/release the lock thousands (or tens or hundreds of thousands) of times per second. You could easily do a quick benchmark to see.

查看更多
爷的心禁止访问
3楼-- · 2019-06-06 11:27

The rate you give (four times a second) won't cause a problem, but you can't use critical sections across processes. You need a kernel level synchronization object like a mutex.

查看更多
再贱就再见
4楼-- · 2019-06-06 11:41

At this rate there definitely not! This is extremely slow, however I'm not sure Critical section is what you want to use, the way I remember it that only ensures thread safety, not cross-application safety, you should look for something else to lock shared memory. You have to use some Inter-Process Communication (IPC) mechanism to ensure atomic operations with shared memory.

查看更多
登录 后发表回答