Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #14218

use unintialized_copy where is initialized

From Stanley Rice <heconghui@gmail.com>
Newsgroups comp.lang.c++
Subject use unintialized_copy where is initialized
Date 2012-02-17 19:03 -0800
Organization http://groups.google.com
Message-ID <6193789.0.1329534189450.JavaMail.geo-discussion-forums@pbie8> (permalink)

Show all headers | View raw


`the difference between *uninitialized_copy* function and *copy* is that the 
*uninitialized_copy* function could copy the object at the location where 
is uninitialized. For example:

    int ia[5] = {1, 2, 3, 4, 5};
    int n = sizeof ia / sizeof *ia;
    int *ib = (int *)malloc(n * sizeof *ia);
    uninitialized_copy(ia, ia + n, ib);

My question is, what if I copy the initialized memory by calling the 
uninitialized_copy function. Instead of allocatiing the memory by calling 
malloc, I use new.
    int *ib = new int[n];
    uninitialized_copy(ia, ia + n, ib);

I works too. But am i correct? If so, what's the difference between copy 
and uninitialized_copy? 

Thanks.

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

use unintialized_copy where is initialized Stanley Rice <heconghui@gmail.com> - 2012-02-17 19:03 -0800
  Re: use unintialized_copy where is initialized Paavo Helde <myfirstname@osa.pri.ee> - 2012-02-18 03:05 -0600

csiph-web