If the other algorithm expects a new'd char buffer that it then frees itself this is true (although it speaks of poor design of the other algorithm).
If you just need to pass a char * or const char * and you handle the delete yourself then this is not true. You can use a std::vector which has the same memory footprint as an array, i.e. this is valid
-
void function(const char *data);
-
-
char *pointer = new char[50];
-
-
std::vector<char> vec(50);
-
-
function(pointer);
-
function(&pointer[0]);
-
function(&vec[0]);
-
Allocating 1000000 bytes to packet seems extremely poor as is copying 500 bytes out of line. All of these sizes can be based on std::string::size to get the actual size required.
"out of memory"
Do you ever free the memory allocated to packet or do you just keep on allocating more? Memory allocation needs to be handled carefully which is why you should try to minimise it where possible or better still hand it off to code that handles it for you like std::vector.