Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Class wrapper

Posted on 2002-03-19
5
299 Views
Last Modified: 2010-04-02
Hi, experts!


I have to adapt some product to new operating environment. The product consists of machine independent core (a lot of code) and machine dependent layer.
The only problem I have adapting the core layer, that the size of stack on the new machine is very small. There are several large classes, and lots of functions that use them as local variables, so in many cases nested calls will cause stack overflow.

My main idea is to create some wrapper class (like smart ptr) that will replace a real class. When it used locally, wrapper will allocate memory from the heap, instead of stack, and delegate method calls to the real class.
Something like this:
CHugeClass
{
     int f();
}
I rename it to
CRawHugeClass
Than create a new
CHugeClass
{
     CHugeClass() {m_p = new CrawHugeClass;}
     int f() {m_p->f();}
     //here I have a problem with class members!!!
}

So I need to change several class definitions instead of many KLines :) of code;

I am looking for an idea how to deal with class members of CHugeClass in this case,
or any better idea at all.

Thank you in advance.
0
Comment
Question by:jemax
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6880828
What about making the wrapper a 'friend' of the original class? That should actually work...
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6880895
If you have a lot of inter-dependent classes this method could turn out to be a nightmare and also cause headaces with maintenance later. If you have only a few class (10 or less,  I would guess) then it's OK

More than that I would rather go the long route and go through the many KLines of code and do it the "proper" way. This way is much more modular anyway. You change one function, see if it works, move on to the next etc.

You should be able to write a little "conversion" utility without too much hassle.
0
 
LVL 6

Accepted Solution

by:
thienpnguyen earned 200 total points
ID: 6881133
Idea : Using reference

Example :

#include <memory>
using namespace std;

class Foo
{
public:

    void f() {};
    void g() {};

private:
    int arr[2000];
};


void main(int argc, char **argv)
{
    // using reference
    auto_ptr<Foo> sp( new Foo )
    Foo & obj = *sp;
    obj.f();
    obj.g();
   



    // Short cut
    Foo & foo = *auto_ptr<Foo>( new Foo );
    foo.f();
    foo.g();

}

0
 
LVL 1

Author Comment

by:jemax
ID: 6884269
Thank you for your comments.

jkr:
it is not an issue of members visibility. Operator '.' in CWrapper should select a member from CReal.

LoungeLizard:
There is a dozen of large classes. I agree, going over the code is the best way, but it must be done in short time.
Utility...
C c, *pc; //keep all decl. in mind for correct replacement
C& rc1 = *pc, rc1 = c;
c. , &c , f(C* pc), f(C c)
et_c :)
I am afraid it will not be small, but "fully functional":) c++ parser

thienpnguyen:
It is great idea, but I still have to change all the functions, because of "= *sp;" :(
Anyway, it is the best comment. If there is no greater solution in a couple of days, the points are yours.

Thanks.
   


0
 
LVL 1

Author Comment

by:jemax
ID: 6884283
Thank you for your comments.

jkr:
it is not an issue of members visibility. Operator '.' in CWrapper should select a member from CReal.

LoungeLizard:
There is a dozen of large classes. I agree, going over the code is the best way, but it must be done in short time.
Utility...
C c, *pc; //keep all decl. in mind for correct replacement
C& rc1 = *pc, rc1 = c;
c. , &c , f(C* pc), f(C c)
et_c :)
I am afraid it will not be small, but "fully functional":) c++ parser

thienpnguyen:
It is great idea, but I still have to change all the functions, because of "= *sp;" :(
Anyway, it is the best comment. If there is no greater solution in a couple of days, the points are yours.

Thanks.
   


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question