?
Solved

Class wrapper

Posted on 2002-03-19
5
Medium Priority
?
302 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
[X]
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
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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.
Suggested Courses

762 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