I have an application which can be launched multiple times simultaneously on Windows.
In this application, at the beginning, we call GlobalAllocPtr() to allocate a memory as below:
// allocate a structure
LPSlcDataMgr lpMgr = (LPSlcDataMgr)GlobalAllocPtr(GHND, sizeof(TSlcDataMgr));
We tested on two machines (both are XP professional 2002, one is SP2 , the other is SP3开发者_StackOverflow社区) but on SP3, our applications will crash randomly
After investigation, we found:
- on SP3 ,
GlobalAllocPtr()
always return the same address for different application processes - but on SP2, it is ok, return different address for each process
Is it possible the GlobalAllocPtr()
returning the same address on WinXP SP3 be the direct or indirect cause of our crash?
Thanks in advance.
For the last 15 years or more, every sane OS has used virtual memory. Every process gets a full virtual address space to itself. So two different processes can have pointers to the same address without any problems or conflict. They never see each others' data, because they each have their own "copy" of that address, and every other address.
That's just how the OS works, and unless you're writing a kernel-mode driver, you don't need to know what the underlying physical addresses are, and you generally don't know what the underlying physical addresses are.
And no, this does not lead to crashes. Your problem is something else.
Memory management has moved on from Windows 3.1:
Windows memory management does not provide a separate local heap and global heap. Therefore, the GlobalAlloc and LocalAlloc functions are essentially the same.
http://msdn.microsoft.com/en-us/library/aa366574(VS.85).aspx
Read the sections about file mapping for creating shared memory between processes,
http://msdn.microsoft.com/en-us/library/aa366551(VS.85).aspx
精彩评论