4/07/2007

04-07-07 - 2

Here's a nasty bug to avoid : DLL Shared data only works if it's *initialized*. Uninitialized data will just silently not be shared. So evil. So like this works :


#pragma data_seg(".SHARED")

char buffer[80] = { 0 };

#pragma data_seg()
#pragma comment(linker, "/section:.SHARED,rws")

And this will appear to work just fine but not actually be shared :


#pragma data_seg(".SHARED")

char buffer[80];

#pragma data_seg()
#pragma comment(linker, "/section:.SHARED,rws")

One thing I'm actually not sure about is whether you can put C++ classes with constructors in the DLL shared data space and have that work right (eg. be shared, and just be constructed/destructed once when the last DLL instance dies).

No comments:

old rants