user-friendly
user-friendly

Reputation: 13

DirectSoundBuffer8::Lock/Unlock

My question is generally about how the behavior of Lock and Unlock method of DirectSoundBuffer8 like.

I have something like this:

unsigned char *bufferPtr;

result = ((IDirectSoundBuffer8*)dsb)->Lock(0,size,(void**)&bufferPtr,(DWORD*)&size, NULL, 0, 0);
if(FAILED(result)) {
    return;
}
memcpy(bufferPtr, waveData, size);
result = ((IDirectSoundBuffer8*)dsb)->Unlock((void*)bufferPtr, size, NULL, 0);
if(FAILED(result)) {
    return;
}
delete[] bufferPtr;

Do I have to really do delete[] bufferPtr; even if it is not made with new?

I compile my program using mingw. The 32-bit runs OK with the delete[] bufferPtr; but in the 64-bit build, it crashes.

Hope someone can enlighten me. Thanks in advance!

Upvotes: 1

Views: 263

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37152

No, you absolutely don't have to do delete[] bufferPtr. You don't own that memory, and once you've called Unlock your pointer to it is not even valid any more.

Upvotes: 1

Related Questions