Can I reliably use memset and memcpy operators in C++ with memory been allocated with new?
Edited:
Yes, to allocate native data type
Example
BYTE *buffer = 0;
DWORD bufferSize = _fat.GetSectorSize();
buffer = new BYTE[bufferSize];
_fat.ReadSector(streamChain[0], buffer, bufferSize);
ULONG header = 0;
memcpy(&header, buffer, sizeof(ULONG));
So long as you are only using new to allocate the built-in and/or POD types, then yes. However, with something like this:
then you would be looking at disaster.
I have to ask though, why you and others seem so enamoured with these functions – I don’t believe I ever use them in my own code. Using std::vector, which has its own copy and assignment facilities seems like a better bet for memcpy(), and I’ve never really believed in the magic of setting everything to zero, which seems to be the main use for memset().