C
Christian Chrismann
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
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