473,511 Members | 16,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

efficiency of a non-polymorphic inheritence

Hi,
I am inheriting a vector<Pointclass as a PointVector
non-polymorphically, to add several additional functionalities to it.
I know the dangers of inheriting a container class, as it doesn't
have a virtual destructor from a previous post by me, and thus it is
designed as a safe way.
As the PointVector is non polymorphic (and its runtime typeid also
shows the same), can I assume it is as efficient as a typedef to
vector<Point? i.e no vtable, and no additional function call overhead
?
As this class is going to be used for some of my critical computation,
I need to avoid any such kind of overhead.

Thanks
abir

Nov 14 '06 #1
6 1501
toton wrote:
I am inheriting a vector<Pointclass as a PointVector
[...]
As this class is going to be used for some of my critical computation,
I need to avoid any such kind of overhead.
You can assume all you want, but when it comes to performance, you need
to measure first and draw conclusions next. Optimize what is proven
unoptimal [by measuring], not what somebody might think is unoptimal.

There are many things that improve the performance of a program that
makes use of 'vector', including but not limited to compiler switches,
avoiding unnecessary copying, processor cache management... I assure
you, virtual function dispatch mechanism is probably going to be the
least of your worries, when you're done implementing all functionality.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 14 '06 #2

toton wrote:
Hi,
I am inheriting a vector<Pointclass as a PointVector
non-polymorphically, to add several additional functionalities to it.
I know the dangers of inheriting a container class, as it doesn't
have a virtual destructor from a previous post by me, and thus it is
designed as a safe way.
As the PointVector is non polymorphic (and its runtime typeid also
shows the same), can I assume it is as efficient as a typedef to
vector<Point? i.e no vtable, and no additional function call overhead
?
As this class is going to be used for some of my critical computation,
I need to avoid any such kind of overhead.

Thanks
abir
You will have to write new constructors, so maybe there will be an
overhead when calling the base class constructors.
Assignment operator is not inheritable, so this will have to be
re-coded.

I am also interested in answers to your question.

Why would you not use composition ?

That way you could possibly change the internal container, the vector,
in the future much more easily.

I'll be wathcing this space .

N

Nov 14 '06 #3

Nindi wrote:
toton wrote:
Hi,
I am inheriting a vector<Pointclass as a PointVector
non-polymorphically, to add several additional functionalities to it.
I know the dangers of inheriting a container class, as it doesn't
have a virtual destructor from a previous post by me, and thus it is
designed as a safe way.
As the PointVector is non polymorphic (and its runtime typeid also
shows the same), can I assume it is as efficient as a typedef to
vector<Point? i.e no vtable, and no additional function call overhead
?
As this class is going to be used for some of my critical computation,
I need to avoid any such kind of overhead.

Thanks
abir

You will have to write new constructors, so maybe there will be an
overhead when calling the base class constructors.
Assignment operator is not inheritable, so this will have to be
re-coded.

I am also interested in answers to your question.

Why would you not use composition ?

That way you could possibly change the internal container, the vector,
in the future much more easily.

I'll be wathcing this space .

If you had a pimpl to your vector and all your pimpl methods were
inlined then there should be no overhead right ?

Nov 14 '06 #4
Nindi wrote:
toton wrote:
Hi,
I am inheriting a vector<Pointclass as a PointVector
non-polymorphically, to add several additional functionalities to it.
I know the dangers of inheriting a container class, as it doesn't
have a virtual destructor from a previous post by me, and thus it is
designed as a safe way.
As the PointVector is non polymorphic (and its runtime typeid also
shows the same), can I assume it is as efficient as a typedef to
vector<Point? i.e no vtable, and no additional function call overhead
?
As this class is going to be used for some of my critical computation,
I need to avoid any such kind of overhead.
>
Thanks
abir
If OP wants to use it as a vector but also have additional
functionality, the simplest thing is to write a number of
free-functions that work with the public interface of vector, as that's
pretty much what he's doing anyway.

The existing algorithms in the standard library already do exactly
that, except they are often generic enough to work with the vector's
iterators.

Nov 14 '06 #5

Earl Purple wrote:
Nindi wrote:
toton wrote:
Hi,
I am inheriting a vector<Pointclass as a PointVector
non-polymorphically, to add several additional functionalities to it.
I know the dangers of inheriting a container class, as it doesn't
have a virtual destructor from a previous post by me, and thus it is
designed as a safe way.
As the PointVector is non polymorphic (and its runtime typeid also
shows the same), can I assume it is as efficient as a typedef to
vector<Point? i.e no vtable, and no additional function call overhead
?
As this class is going to be used for some of my critical computation,
I need to avoid any such kind of overhead.

Thanks
abir
>

If OP wants to use it as a vector but also have additional
functionality, the simplest thing is to write a number of
free-functions that work with the public interface of vector, as that's
pretty much what he's doing anyway.

The existing algorithms in the standard library already do exactly
that, except they are often generic enough to work with the vector's
iterators.
That apeals alot more to me, for one its simpler !!!! and with
hindsight its more obvious.
But I would still typedef it.

Nov 14 '06 #6

Nindi wrote:
toton wrote:
Hi,
I am inheriting a vector<Pointclass as a PointVector
non-polymorphically, to add several additional functionalities to it.
I know the dangers of inheriting a container class, as it doesn't
have a virtual destructor from a previous post by me, and thus it is
designed as a safe way.
As the PointVector is non polymorphic (and its runtime typeid also
shows the same), can I assume it is as efficient as a typedef to
vector<Point? i.e no vtable, and no additional function call overhead
?
As this class is going to be used for some of my critical computation,
I need to avoid any such kind of overhead.

Thanks
abir

You will have to write new constructors, so maybe there will be an
overhead when calling the base class constructors.
Assignment operator is not inheritable, so this will have to be
re-coded.
I don't need container assignment. Constructor is one time call. All I
need is a frequent access (either through iterator or direct indexing)
, and add & remove elements (for which I want additional methods rather
than push_back ).
I am also interested in answers to your question.

Why would you not use composition ?
Oh! Absolutely possible. Only it is tedious, and need to forward each
call ( and hence may be some overhead).
Check a previous post by me and expert answers by Kai-Uwe Bux. I
preferred his over Pete Becker's .
http://groups.google.com/group/comp....ae69eaa3d56c96
That way you could possibly change the internal container, the vector,
in the future much more easily.

I'll be wathcing this space .
Thanks
N
Nov 15 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
1642
by: JKop | last post by:
Your program begins at: int main(void); Now, in main, you want to call a function. This particular function you want to call defines a local object of type Taste, and then returns this local...
31
2587
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant...
9
4599
by: Peng Jian | last post by:
I have a function that is called very very often. Can I improve its efficiency by declaring its local variables to be static?
2
1874
by: Wysiwyg | last post by:
I was hoping to get some opinions on the efficiency of various methods of reusing the same dropdown list data. Here is the situation: Multiple panels on maintenance pages with TAB menus across...
335
11445
by: extrudedaluminiu | last post by:
Hi, Is there any group in the manner of the C++ Boost group that works on the evolution of the C language? Or is there any group that performs an equivalent function? Thanks, -vs
9
2045
by: burningsunorama | last post by:
Hi guys! This is maybe a too 'academic problem', but I would like to hear your opinions, something like pros and cons for each approach.... ... Recently we've had at work a little talk about the...
83
3558
by: Licheng Fang | last post by:
Hi, I'm learning STL and I wrote some simple code to compare the efficiency of python and STL. //C++ #include <iostream> #include <string> #include <vector> #include <set> #include...
2
1184
by: yicong | last post by:
hi,All could you tell me which case is more efficiency?(my tables have no index) And does it has any else case more efficiency? case1: "select sum(Invoice_Production.Quantity) from...
0
1205
by: Laurent Deniau | last post by:
I was wondering if there is any good reason (semantic) to assume that the following three code do not have the same efficiency (both space and time): struct A { int a,b,c; }; // could other...
5
244
by: Lars | last post by:
I need to multiply to large matrices (of type double), where one is "dense" (mostly non-zero entries) and the other is "sparse" (mostly zero entries). Will it be more efficient to check for...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5066
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.