Mail Archives: djgpp/1997/03/01/15:39:07
On 1 Mar 1997 18:47:35 GMT, Jeff Weeks <pweeks AT execulink DOT com> wrote:
>I've got a structure:
>
>typedef struct { int h,c; } buf_data;
>
>and I define two variables and allocate memory for them:
>
>tbuf *buf_data;
>bbuf *buf_data;
I'm not very familar with C++. However, the above two points (in C) should be:
buf_data *tbuf;
buf_data *bbuf;
>tbuf = new buf_data[video.max_x];
>bbuf = new buf_data[video.max_x];
>
>and now I want to copy the values from bbuf to tbuf. The following
>should work shouldn't it?
>
>tbuf = bbuf;
>
>because it would copy the address of bbuf into tbuf right? Or am I
>totally wrong? I've tried
tbuf = bbuf will merely have two pointers to the same memory. This will not
copy the contents pointed to by bbuff into the memory allocated by new. In
fact, the memory allocated by the second new will no longer be accessable at
all. To copy memory blocks, the easiest way to is use one of the memory copy
functions such as memcpy(tbuf,bbuff,video.max_x);
- Raw text -