Link to home
Start Free TrialLog in
Avatar of jemax
jemax

asked on

Class wrapper

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.
Avatar of jkr
jkr
Flag of Germany image

What about making the wrapper a 'friend' of the original class? That should actually work...
Avatar of LoungeLizard
LoungeLizard

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.
ASKER CERTIFIED SOLUTION
Avatar of thienpnguyen
thienpnguyen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jemax

ASKER

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.
   


Avatar of jemax

ASKER

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.