does memcpy create a new block of memory?
given two pointers :
Code:
int *p1;
int *p2;
p1 = new int[10];
memcpy(p2,p1,sizeof(p1));
I'm trying to get the program to have p2 it's own memory so that if I do something like p2[0] = 1;
p1 won't be affected.
Does memcpy create a new memory block like that for me? If not, what does?
<-- trying to aviod constant creation of memory
Re: does memcpy create a new block of memory?
Quote:
Originally posted by Diamonds
Code:
<-- trying to aviod constant creation of memory
well then how are you suppose to have p2 its own memory if you are trying to avoid that...well for me..i dont know much functions of other things so i write my own for loops for copying for arrays
Re: does memcpy create a new block of memory?
Quote:
Originally posted by Diamonds
given two pointers :
Code:
int *p1;
int *p2;
p1 = new int[10];
memcpy(p2,p1,sizeof(p1));
I'm trying to get the program to have p2 it's own memory so that if I do something like p2[0] = 1;
p1 won't be affected.
Does memcpy create a new memory block like that for me? If not, what does?
<-- trying to aviod constant creation of memory
No, memcpy simply copies the contents of one chunk of memory to another.
int a = 12, b = 75;
memcpy(&a, &b, sizeof(int));
cout << a << endl; // prints '75'
cin.get();