Memory and Thread

Hello,
I realize a client-serv UDP in c++ with VS8. The data sand size can be very different: 10o to 1Mo.
My program has two threads who do the communication. The reception thread has a problem during the data reconstruction. The program refuse to allocate memory: it bug: wrong access memory.
Like i said before, data size are not fixed so i need dynamic memory. For this i tried to use vector<char> and char* but together do a memory bug.
Do you know if it s possible to use dynamic memory in a thread or if this is restrict? or others ideas?

Thanks for your reading.
Have Good day.

Gilgamesh
std::string > vector<char> I would think

If you are using an std::string you won't need to deal with char* conversions, you can just use .c_str().
Sorry i just wanted say i have try to save my data with vector<char> but it doesn t fonction so i tried after with char* in a second version. I didn t need to do conversion.

And when i do a puchback for example for the vector or a memcopy for the char* for the second version i have a memory bug. For the vector it cann t alocate a new char place

It s very strange because if i run my program in main fonction it fonction but in a thread memory bug :(
I just test with string it s same than with vector.
A string define 15chars by default if i try to add 16 or resize BUG.
I have found the problem.

I created my var in the thread stack and i didn t know threads can t share this stack.
So solution pass all var in pointer like all is in the ram. And no pb of writting.
Topic archived. No new replies allowed.