I got a code snippet out of "Tricks of the 3D Game Programming Gurus: Advanced 3D Graphics and Rasterization". It replaces memset(), but when I use it I access violations (I believe that I'm using it incorrectly). Its supposed to clear by QUADs instead of BYTEs (or something like that.) Here are the snippet and a second one that I made:
inline void SetMemory(void* pDest, UINT nData, int iSize)
{
_asm
{
mov edi, pDest;
mov ecx, iSize;
mov eax, nData;
rep stosd;
}
}
inline void ClearMemory(void* pDest, int iSize)
{
SetMemory(pDest, 0, iSize);
}
I then tested it with
WNDCLASS WndClass;
dftCommon::ClearMemory(&WndClass, sizeof(WNDCLASS));
Which clears the memory perfectly (just like ZeroMemory(), but after the app returns from main(), I get a large amount of access violations. After switching to ZeroMemory(), they go away. Any ideas?
Thanks!
[Edited by - Programmer16 on July 4, 2005 1:14:40 PM]