473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Copying STL Lists

Hi,
what is the easiest way to copy a STL list of BYTEs to a new list that will
then be used and maintained by an external class? The list that is to be
copied is very large about 25000 so the I need a very efficient solution.

many thanks,
Jul 22 '05 #1
4 1376
Harry Overs wrote:
what is the easiest way to copy a STL list of BYTEs to a new list that will
then be used and maintained by an external class? The list that is to be
copied is very large about 25000 so the I need a very efficient solution.


Depending on whether you want to retain the original list or not, using
'list::swap' or 'std::copy' is probably what you should consider.

You could also read more about "move semantics" in c.l.c++.moderated, in
archives.

Victor
Jul 22 '05 #2
Harry Overs wrote:
Hi,
what is the easiest way to copy a STL list of BYTEs to a new list that will
then be used and maintained by an external class? The list that is to be
copied is very large about 25000 so the I need a very efficient solution.


(assuming typedef char BYTE)
std::list<BYTE> is not exactly the most efficient way to store bytes and
25000 bytes is really quite small on some more modern systems.

I would probably just use list::size() to find the size, allocate a
vector or array (whatever is needed) and use std::copy or std::copy_n.

If the performance was not good enough, I'd do a profile and figure out
what was using the the cpu and fix that. Doing anything else right now
is speculative.
Jul 22 '05 #3
Harry Overs wrote:
Hi,
what is the easiest way to copy a STL list of BYTEs to a new list that
will
then be used and maintained by an external class? The list that is to be
copied is very large about 25000 so the I need a very efficient solution.

many thanks,


Why not use simple assignment? The operator=() actually will make a copy of
the list:

#include <list>
#include <iostream>

int main ( void ) {
std::list< int > a, c;
a.push_back( 1 );
std::list< int > b = a;
b.push_back( 2 );
c = a;
std::cout << c.size() << " " << b.size() << '\n';
}

As for efficiency, please profile your program first and tell us about your
findings. Otherwise it is hard to suggest solutions (in fact, it is hard to
tell whether there is a problem to begin with).
Best

Kai-Uwe Bux
Jul 22 '05 #4
"Harry Overs" <ho****@dera.gov.uk> wrote in message news:<cj**********@hamble.qinetiq.com>...
Hi,
what is the easiest way to copy a STL list of BYTEs to a new list that will
then be used and maintained by an external class? The list that is to be
copied is very large about 25000 so the I need a very efficient solution.

many thanks,


with = or list::assign
Hope this help
Jul 22 '05 #5

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

Similar topics

23
by: Francis Avila | last post by:
Below is an implementation a 'flattening' recursive generator (take a nested iterator and remove all its nesting). Is this possibly general and useful enough to be included in itertools? (I know...
0
by: Bennett Haselton | last post by:
I'm trying to port my MySQL tables for a database called "tracerlock" from one server to another. On the old server, in the /var/lib/mysql/tracerlock directory, there was a ".MYD", ".MYI" and...
0
by: Ville Mattila | last post by:
Hi everyone, Is there any easy way to duplicate a row in a table with auto increment column, that shouldn't of course be copied. I tried a query "NSERT INTO table SELECT * FROM table" but it...
8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
3
by: TM | last post by:
I have two datagrids in my application where one grid is for the master item list and the second grid is for a shopping list. I would like to click on a button and copy items from the master list...
8
by: zefciu | last post by:
Hello! Where can I find a good explanation when does an interpreter copy the value, and when does it create the reference. I thought I understand it, but I have just typed in following...
4
by: lucoto | last post by:
Hi, Can anyone explain me how to copy a XmlTextReader object instead of copying a reference to it? I tried to use MemberwiseClone() method but it doesn't make a deep-copy as well.. and ICloneable...
5
by: pallav | last post by:
I have a map like this: typedef boost::shared_ptr<NodeNodePtr; typedef std::vector<NodePtrNodeVecPtr; typedef std::map<std::string, NodePtrNodeMap; typedef std::map<std:string,...
1
by: cnb | last post by:
Is it not possible to have mutability without this? I know I can use sorted and list(reversed) instead of .sort and .reverse but if I want to copy a list and then change that list without changing...
1
by: Mike P | last post by:
I have been asked to create an application that copies folders on a network from one location to another, based upon a text file on the network that lists folder name, destination, and copy...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.