メンバー変数 pointer を作成するとしますpBuffer
。このバッファを未知の土地に送り、データで埋めます。ここで、pBuffer に任意の量のデータがあるとします。
Q: pBuffer が占有していた不要なメモリをすべて解放しながら、pBuffer を完全に削除せずにリセットする方法はありますか?
例:
class Blah
{
public:
unsigned char* pBuffer;
Blah(){pBuffer = NULL;}
~Blah(){}
FillBuffer()
{
//fill the buffer with data, doesn't matter how
}
ResetBuffer()
{
//????? reset the buffer without deleting it, still deallocate memory ?????
}
};
int main()
{
Blah b;
b.FillBuffer();
b.ResetBuffer();
b.FillBuffer(); //if pBuffer were deleted, this wouldn't work
}