472,805 Members | 1,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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 2820
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
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
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
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
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
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
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
by: utab | last post by:
Dear all, In programming terminology, what is a wrapper and where is it used? Regards
4
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
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++...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.