views:

155

answers:

2

I have some programs that use MapViewOfFile to share data, but I am getting strange access violations that seem to be from accessing the mapped file data.

Some of the shared data has pointers, however these pointers are only set and used by one process, but by several threads within the process.

I understand that you can't use pointers in mapped view across different processes, as obviously they could be mapped to different memory for each process, but is it safe to use pointers in mapped memory between threads on the same process?

A: 

Yes, it is safe to share pointers (in mapped memory or not) between threads in the same process, since the threads share the same address space.

Paul Baker
+1  A: 

You can share pointers among threads within the same process. Just make sure you protect the shared memory with a lock, such as a critical section. Simultaneous access of the shared memory by multiple threads - especially if one or more of the threads are updating the memory - can easily cause access violations.

PapaBoojum