Jump to content
  • Advertisement
Sign in to follow this  
antareus

Unity Process-wide global (part 3)

This topic is 4946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Continuing my older discussion, thought someone might find this interesting. The rationale was maintaining a single instance of a struct across an entire application *without* any external DLLs. There are a few concerns: 1. separate heaps - the worst case scenario is where one module initializes the runtime structure, and another ends up freeing it. I used the HeapAlloc() and HeapFree() API functions to transcend DLL boundaries and let users run whatever runtime library they wish to use. 2. discovering the address - this was a big sticking point. I wanted to use environment variables, but I had trouble sticking whatever I wanted in there. SetEnvironmentVariable() would stop storing the pointer address once it saw a null byte. I wrote a SerializablePtr template that is designed to store a process-wide pointer in environment variables by maintaining the invariant that the first five bytes are guaranteed to be non-zero. We have to contort the pointer address if it has null bytes in it, and store the changes in the lead byte. The last byte is a null byte, signalling the end of the "string." The result is a "string" that isn't human readable, but pretty fast to unpack. I tested it on Win98, as well as on XP, and it seemed to work fine. It is somewhat sketchy, but MSDN does not specify that the string must be composed of ASCII characters. 3. versioning - what if I rearranged the struct layout? What if one user is running version 1.0 of the library, and another is running 1.1? I decided that even though this is a header-only library, side-by-side execution should be possible. The environment variable name subsequently has the version number contained within it. Any data contained within it is specific to that version. Thoughts/comments/concerns welcome. I realize this is esoteric subject matter, but perhaps someone will derive inspiration for it. Happy New Year.

Share this post


Link to post
Share on other sites
Advertisement
What happens when you run into process that are started with their own environment variable block, and/or don't inherit the system environment?

Share this post


Link to post
Share on other sites
Adding an env variable with a name that isn't in the table will create it right then. I just store the TLS index in the env table now and use a Meyers singleton-like method to cache the pointer in each translation unit.

Share this post


Link to post
Share on other sites
This is for your plugin system for OpenIM, right?

I'm still not sure exactly why you want to go about doing this

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Nope, this is separate. Trying to formalize and release my class library for Win32, styled a bit after Qt/Wx/.NET's class libraries. Also trying to subvert link-time requirements for the internal machinations required to implement niceties such as asychronous timers while still generating small executables.

We'll see what the definition of small is going to be. I'm shooting for under 100k in a fairly basic application.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!