Sign in to follow this  
easyBob0101

Data betwee objects

Recommended Posts

I did a search, but I don't think I used the right keywords for what I need, so I'll explain. I have a class that gets used a lot. In this class is a lookup table(loaded from a file) that can be very very big. Now, I don't want that lookup table to load every time I create an object of that class. So, how do I load that table once and have all the instances be able to access it? Oh, and if there is a solution, does it have a name? I just don't want to fill up memory with useless data. Thanks, -Chris

Share this post


Link to post
Share on other sites
SiCrane, I'm using C++/CLI, or whatever...managed C++ is what I call it. :shrug:

TheUnbeliever, I thought about that, but I just don't think that is best.

ClassA a1 ("slkdfj", table);
ClassA a2 ("gfagf", table);
ClassA a3 ("ggwv", table);
ClassA a4 ("slvbekdfj", table);

That just looks so inefficient.

Logically, this class, and only this class need the lookup table, just not multiple copies of it in memory.

What I would like to see is the table loaded on the first instance of the class, and the rest just use that....

-Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by jeff75225
In C++ you would declare the table as static....I think that is the word you were looking for


Yes! I do believe that is it! Thank you all!

"When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class."

-Chris

Share this post


Link to post
Share on other sites

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

Sign in to follow this