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

Home Posts Topics Members FAQ

wrapper class for STL lists

Hi,

an application uses a wrapper class for an STL list. Basically,
this template class provides the same functions (delete, append, find...)
as an ordinary STL list. Additionally, there are some convenient functions
for iterating through the list.

For instance, to go through all elements of the list (after fetching the
first list element), the class provides a function that looks as follows:

template <class ELEMENT>
ELEMENT* myList<ELEMENT>::GetNextElement()
{
if (mylist.empty() || current_elem == NULL)
{
current_elem = NULL;
return NULL;
}

ELEMENT *element = *current_elem;

if (current_elem != (--(mylist.end() ) ) )
++current_elem;
else
current_elem = NULL;

return element;
}

The fast access to the next list element is given by "current_elem". This
is just an iterator pointing to an element of the wrapped STL list in the
class myList:

list<ELEMENT*>::iterator current_elem;

I've profiled an application that uses this wrapper class "myList" with
gprof and figured out that a substantial fraction of the program run-time
is spent in the function "GetNextElement" and some other function of the
class myList. I suppose that this wrapper class is not very efficient
since the iterator "current_elem" has to be adjusted at many porgram
points in order to update the currently considered list element. So, the
benefit of having a pointer to the current element and saving searching
for it in the list is degraded by the frequent update of the iterator.

Are you of the opinion that this wrapper class is redundant and that it
might be implemented more efficiently when pure STL lists and their
functions would be used?

Regards,
Chris




Aug 14 '06 #1
2 2858
Christian Chrismann wrote:
an application uses a wrapper class for an STL list. Basically,
this template class provides the same functions (delete, append,
find...) as an ordinary STL list. Additionally, there are some
convenient functions for iterating through the list.
What's the convenience of them? What's not convenient about, say,
'std::list::erase' or 'std::list::push_back'?
For instance, to go through all elements of the list (after fetching
the first list element), the class provides a function that looks as
follows:
Why? What's not fitting about 'std::for_each'?
template <class ELEMENT>
ELEMENT* myList<ELEMENT>::GetNextElement()
{
[..]
}

[..]
I've profiled an application that uses this wrapper class "myList"
with gprof and figured out that a substantial fraction of the program
run-time is spent in the function "GetNextElement" and some other
function of the class myList. I suppose that this wrapper class is
not very efficient since the iterator "current_elem" has to be
adjusted at many porgram points in order to update the currently
considered list element. So, the benefit of having a pointer to the
current element and saving searching for it in the list is degraded
by the frequent update of the iterator.

Are you of the opinion that this wrapper class is redundant and that
it might be implemented more efficiently when pure STL lists and their
functions would be used?
I am of the opinion that reinveting the wheel, especially if the results
are not satisfactory, is a waste of time.

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

Christian Chrismann skrev:
Hi,

an application uses a wrapper class for an STL list. Basically,
this template class provides the same functions (delete, append, find...)
as an ordinary STL list. Additionally, there are some convenient functions
for iterating through the list.
This makes me wonder why you wrap it at all.
>
For instance, to go through all elements of the list (after fetching the
first list element), the class provides a function that looks as follows:

template <class ELEMENT>
ELEMENT* myList<ELEMENT>::GetNextElement()
{
if (mylist.empty() || current_elem == NULL)
{
current_elem = NULL;
return NULL;
}

ELEMENT *element = *current_elem;

if (current_elem != (--(mylist.end() ) ) )
++current_elem;
else
current_elem = NULL;

return element;
}

The fast access to the next list element is given by "current_elem". This
is just an iterator pointing to an element of the wrapped STL list in the
class myList:

list<ELEMENT*>::iterator current_elem;

I've profiled an application that uses this wrapper class "myList" with
gprof and figured out that a substantial fraction of the program run-time
is spent in the function "GetNextElement" and some other function of the
class myList. I suppose that this wrapper class is not very efficient
since the iterator "current_elem" has to be adjusted at many porgram
points in order to update the currently considered list element. So, the
benefit of having a pointer to the current element and saving searching
for it in the list is degraded by the frequent update of the iterator.
That function does not look as if it is the fastest on the earth. But
you will not get a substantially faster functionality (e.g. twice as
fast) for std::list if it has a reasonable size. Most time spent with
modern processors on large lists is time to read from primary memory
and you can't eliminate that time ever - except by using a structure
different from list.
>
Are you of the opinion that this wrapper class is redundant and that it
might be implemented more efficiently when pure STL lists and their
functions would be used?
Yes. Use std::for_each or one of its cousins.
>
Regards,
Chris
Aug 14 '06 #3

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

Similar topics

4
2766
by: Edvard Majakari | last post by:
Hi, I was wondering what would be the most elegant way for creating a Python class wrapper for a command line utility, which takes three types of arguments: 1. options with values (--foo=bar)...
12
4051
by: Egil M?ller | last post by:
Is there any way to create transparent wrapper objects in Python? I thought implementing __getattribute__ on either the wrapper class or its metaclass would do the trick, but it does not work for...
4
2870
by: Christian Christmann | last post by:
Hi, I need an STL list and was thinking of putting the list in wrapper class. The reason for my decision is that you can much better perform consistency checks. For instance, I need a...
0
1208
by: DotNetJunkies User | last post by:
Background: I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below: Range r = new Range( 2, 2 ); r = new Cell( “Hello Mum” ); Range is a...
9
2396
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for...
2
2276
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 ...
16
3409
by: utab | last post by:
Dear all, In programming terminology, what is a wrapper and where is it used? Regards
4
3084
by: Alex Shulgin | last post by:
Hi, below is near exact copy of my post to png-mng-implement mailing list (png-mng-implement@lists.sourceforge.net). I've got no answer there, so probably there is not much interest in such a...
0
1334
by: Ed | last post by:
Hi, dear all, I want to wrapper the legacy C++ Template Class to be used by the C# code, so I try to wrapper the legacy C++ code into CLI/C++ code first. One problem is how to wrapper C++...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
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
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.

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.