Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ memcpy

Reply
Thread Tools

C++ memcpy

 
 
barcaroller
Guest
Posts: n/a
 
      04-12-2007
Does C++ have an equivalent for C's memcpy? I have two memory blocks
(created using new, not malloc) and I need to copy the contents of one to
the other. The memory blocks are just that; they are not objects.


 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      04-12-2007
barcaroller wrote:
> Does C++ have an equivalent for C's memcpy? I have two memory blocks
> (created using new, not malloc) and I need to copy the contents of one to
> the other. The memory blocks are just that; they are not objects.


Yes, memcpy. The C Standard Library is part of the C++ Standard Library.
 
Reply With Quote
 
 
 
 
Greg Comeau
Guest
Posts: n/a
 
      04-12-2007
In article <evm7ja$7fo$(E-Mail Removed)>, barcaroller <(E-Mail Removed)> wrote:
>Does C++ have an equivalent for C's memcpy? I have two memory blocks
>(created using new, not malloc) and I need to copy the contents of one to
>the other. The memory blocks are just that; they are not objects.


memcpy is part of the C++ Standard Library as well.
If can be accessed via <string.h> or <cstring> and
may or may not need std:: qualification (the standard
is clear on when it's required, but compilers are
across the board on applying it still).
--
Greg Comeau / 4.3.9 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
Reply With Quote
 
Gianni Mariani
Guest
Posts: n/a
 
      04-12-2007
barcaroller wrote:
> Does C++ have an equivalent for C's memcpy? I have two memory blocks
> (created using new, not malloc) and I need to copy the contents of one to
> the other. The memory blocks are just that; they are not objects.


C++ has memcpy.

#include <cstring>

int main()
{
char a[10], b[10];

std::memcpy(a, b, sizeof(a));
}

You can also use std::copy. On some compilers, a std::copy of POD's
will turn into a memcpy.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
memcpy for copying arrays franky.backeljauw@ua.ac.be C++ 13 09-17-2003 11:36 PM
Problem with malloc, realloc, _msize and memcpy Bren C++ 8 09-03-2003 11:01 PM
memcpy problem with padding for word alignment!!! very urgent Ninan Thomas C++ 3 08-22-2003 06:19 AM
Optimized memcpy to reduce cache misses John Edwards C++ 1 08-07-2003 03:01 AM
Re: Optimized memcpy to reduce cache misses David Bradley C++ 0 08-07-2003 12:39 AM



Advertisments