How does shared memory work in a DLL?
When a DLL connects to a process, it uses the same memory addresses as the process. Suppose we have the following function in a DLL:
int * data = 0;
int foo()
{
if (!data) data = new int(random());
return *data;
}
When process A calls this function, it creates a new object (int) and returns its value. But now process B attaches this DLL. It calls foo (), but I don’t understand how it works because it datais in the process. ' How could B use it directly?
source
share