Stack Object

How can I dermine if a class is dynamic memory or in the stack?

The class is a pure virtual class (I want to tell if the derived classes are stack object)
Tomb64Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikeblasCommented:
There's no provision in C++ for this.  You can cobble together something platform-specific, though.  We can't help you with that until we know what version of which compiler you're using on what version of which platform.

..B ekiM
0
jkrCommented:
mikeblas is correct. The only method that comes into my mind applies to MS VC++. It has a '_CrtIsValidHeapPointer()' which could serve this purpose...
0
nietodCommented:
I agree and dissagree.

There are ways that are not platform specific, but usually aren't great.  Most (all?) of these techniques revolve around overloading the new (and maybe delete) operator for the class involved.  The new operator can then do "things" to help track the fact that the object is dynamcicllly allocated.  For example, it may store a pointer to the object in a container of some sort (hash table?).  This table could later be searched for the address to see if the object was dynamically allocated.  The overloaded delete operator would have to remove the object from the table.)  

This sort of approach is a little dangerious though.  There are usually things that a program can do to "get around" the mechanism anc cause it to work improperly, thus it is not fool proof--because fools are so ingenius.  It is usually a better idea to just redesign your program so that this sort of information (whethor or not an object is allocated dynamically) is not needed.

Another solution is to prevent objects from a class from every being dynamically allocated or requiring that they always be dynamically allocated.  There are techniques for these features that are a little safer to use (harder for a programmer to circumvent.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbormannCommented:
I dont knwo much C++,but continuing in the same line as nietod ,in the last paragraph where he has explained ,can be found in Scott Meyer's book 'More Effective C++' (or is it in 'Effective C++' ,i am not sure)

thanks to nietod for his excellent suggestion ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.