End Google Ads 201810 - BS.net 01 -->
I'm working on a GAME SERVER program. there is a design problem confused me.
Basic Situation:
1. the host object just as bellow has a lot of child objects. eg, 20 child objecs.
2. the host would be new and delete very frequently.
3. all the operations from the child would be invoked like this :
pHost->GetA()->DoSomething(),and also very frequently.
4. CHost1 use objects as child,CHost2 use poniter and new child in constructor.
my question is:
1. since I would new and delete CHost very ofen,may be in the server loop, is CHost2 a bad design?
2. since all the method of the child would be invoked like this:
pHost->GetA()->DoSomething(). is this indirect call cost a lot compare to
pHost->DoSomething, because it happens a lot.
If CHost2 is a bad design, I would use CHost1 or use CHost2 and a CHost2 Pool.
If Indirect call cost a lot.I would only use CHost3 without child objects,and all method would be like pHost->Dosomething
Thank you all.
ps I can't use the code button to format the code,I tried chrome and ie,why
class CHost1
{
public:
CHost1(){}
public:
C1* Get1();
C2* Get2();
CN* GetN();
private:
C1 m_1;
C2 m_2;
CN m_n;
};
class CHost2
{
public:
CHost2()
{
m_p1 = new C1;
m_p2 = new C2;
m_pN = new CN;
}
public:
C1* Get1();
C2* Get2();
CN* GetN();
private:
C1* m_p1;
C2* m_p2;
CN* m_pN;
};
مواقع النشر (المفضلة)