5 ms·
Global variables in DLL's are definitely not visible across processes. Each process which attaches a DLL has its own instance, in its own protected address spac
by kazinator 11y ago
Global variables in DLL's are definitely not visible across processes. Each process which attaches a DLL has its own instance, in its own protected address space.
If the claim were true at face value, it would mean that if two programs use, say, MSVCRT.DLL (Microsoft's Visual C run-time), if one program reads from stdin or writes to stdout, it interferes with the other.
- ctstover 11y agoCorrect, normal globals no. There is a way to make some special values have this behavior though. It's been a long time, but I think the reason was to have some analog to the win16 behavior. In that shared-everything universe, there were these IPC through dll patterns.
- kazinator 11y agoWin32 has an API for shared memory that is straightforward to use. You use CreateFileMapping with an INVALID_HANDLE for the file to create a mapping which is like MAP_ANONYMOUS in mmap (not backed by a file). It is not literally anonymous because you can give the mapping a name (similar to, say, a POSIX semaphore name in sem_open). Other processes can attach to the mapping using the name. To actually instantiate the mapping in the address space, you use the MapViewOfFile function. MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366551%28v=vs.85%29.aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa3... Been years since I used this stuff.
- to3m 11y agoYou can set the shared flag on the section. See, e.g., http://www.codeproject.com/Articles/240/How-to-share-a-data-segment-in-a-DLL http://www.codeproject.com/Articles/240/How-to-share-a-data-..., https://msdn.microsoft.com/en-us/library/sf9b18xk.aspx https://msdn.microsoft.com/en-us/library/sf9b18xk.aspx