PDA

View Full Version : How to clear shared memory?



THRESHE
22nd May 2008, 10:47
Hi everyone !

I'm writing something in QSharedMemory in one process and then in the other process I read from it and I want to clear the contents.

How can I do that?

wysota
22nd May 2008, 11:03
Overwrite it with zeroes.

THRESHE
22nd May 2008, 11:29
Thanks for your reply but after a minute after I posted this thread I did like this


char* pPath = (char*)sharedMem_->data();
memset(pPath, '\0', strlen(pPath)+1);

It worked.
Thanks anyway :)

wysota
22nd May 2008, 12:04
Yeah, you have overwritten it with zeroes :] BTW. I wouldn't use strlen() here, if I were you. You might end up clearing only part of the block this way.

THRESHE
22nd May 2008, 19:28
I read only one string from shared memory so I don't mind if the part that is behind my string contains garbage :)