15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Deriving from CObject or not deriving from CObject ? That's

Serge Wautier -- serge.wautier@ontonet.be
Thursday, November 21, 1996

Environment: Windows 95, VC++ 4.1

Hi All,

My documents contain arrays structures.

I'd like to turn these structures to objects in order to improve the
quality of the design.
I wonder what is the overhead of deriving these objects from CObject vs
create them without base class.

In my case, deriving my objects from CObject is interesting for
serialization support but i'm afraid it's a heavy price (in terms of
memory) to pay since the doc can contain up to a few thousands of them. Are
CObject (& CObArray) well suited to handle big amounts of rather small
objects ?

I started my implementation using a CArray. 
If I turn "MyStruct" to "CMyObj : public CObject", it is clear that i
should use CObArray instead of CArray.
But if i don't derive CMyObj from CObject, what array class should i use ?

MFC doc says i can use Carray but it always shows samples
whose CMyObj is derived from CObject.

Any explanation welcome !

Thanks for your help,


Serge Wautier,
Techno Trade s.a.
Belgium
serge.wautier@ontonet.be
http://www.tbox.fr



serge -- iloma@axionet.com
Saturday, November 23, 1996

Serge :

> CObject (& CObArray) well suited to handle big amounts of rather small
> objects ?

CObject class carries very small overhead over no_base class. CObject
deliveries several  fundamental things  such as runtimeinfo and
serialization. In your case, CObject as a base class is what you would
appreciate : collections know how to serialize all their CObject type
elements. If you decide not to use CObject, you still can use CArray, with
CPtrArray instead of CObArray, but you will have to take care of
serialization.

Many developers including myself have practice to  automatically derive new
classes from CObject.

Regards,
Serge Okuntsev.




| Вернуться в корень Архива |