I have a very simple routine (at least should be simple)
I create a large char array and I am copying data to it as I receive it moving. After about the third iteration the app crashes.
first create a large buffer
_buffer = new char(7931880);
...
void writeData(char* newData,size_t size)
{
memcpy(_buffer,newData,size); //this call succeeds the first 4 times then fails bytes received
_buffer+=size; //(size) is never larger than 16000
}
_buffer = new char(7931880);
or should it be_buffer = new char[7931880];
memcpy
is generally inadvisable in C++; usestd::copy
instead.std::copy
works in general,memcpy
only works on POD types. Plus it doesn't require you to think about size.new T()
tonew T[]
, usestd::vector<T>
instead ofnew T[]
.