I have an array and also a buffer of char*
I have memcpy from buffer into the array, is this ok or should i memcpy into another buffer of char* and free it when done?
I dont have to free an array after a memcpy as not technically a pointer.
I have an array and also a buffer of char*
I have memcpy from buffer into the array, is this ok or should i memcpy into another buffer of char* and free it when done?
I dont have to free an array after a memcpy as not technically a pointer.
No problem. The only thing you need to worry about is if your array is big enough to hold all the data you're copying.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Grand cheers for that, just couldnt remember if it was ok or not. Size is grand as all taken care of!
Thanks
The only thing to watch out for with memcpy() is to make sure that source and destination do NOT overlap.
If they're two separate buffers, then it's not a problem.
But if you're trying to move the tail of a buffer to the head (so you can add more data), then memcpy() is the wrong thing to use. Use memmove() in this case.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.