Jump to content
DavidJr.

A better way to share global data structures than as global variables?

Recommended Posts

4 hours ago, mvanrijnen said:

post deleted?

 

Looks like it. There was another post by the same account in a different topic that also looked auto generated but had an extra sentence not really on topic with a link to a commercial software/service website. 

Share this post


Link to post
4 hours ago, Brian Evans said:

Looks like it. There was another post by the same account in a different topic that also looked auto generated but had an extra sentence not really on topic with a link to a commercial software/service website. 

This is classic AI spammer tactic. Post AI on random posts to make it look like user is actively participating, and then separately they also post blatant spam.

  • Like 1

Share this post


Link to post
On 1/27/2022 at 8:09 AM, Fr0sT.Brutal said:

You don't have full and flexible control over when a DM is created

Yes you do, as long as you have the source code. You have complete control over when a DM is created.

Share this post


Link to post
On 3/8/2022 at 9:01 PM, Steven Kamradt said:

In your case, I would put the variables you are working with in a class or even a record and set the scope to what you selected as private to the thread.  Keep it simple, its all about preventing access from multiple threads.  If you have a global variable that needs to be accessed by multiple threads, protect the access using some sort of semaphore, such as a critical section or spin lock.

Before anyone gets too upset, my perspective is based on dealing with legacy code you have come into. There are numerous advantages to encapsulating global variables. Not only do you establish a measure of access control, but if you expose them as properties with getters and setters, you can easily set breakpoints to discover points of interaction. Equally, you could introduce logging. But even without those benefits, you will be altering the calling code to reference MyGlobals.SomeState, rather than simply SomeState. Once you have accomplished that tedious task, it is also a simple matter to search for all such references by searching on MyGlobals.

 

Other benefits will become apparent as you work through things.

  • Like 4

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×