我看到這個question的答案是非常受歡迎的關於如何打印簡歷::墊圖像到MFC應用程序。這會泄漏內存嗎?我怎樣才能防止它?
不過,我想知道是否有內存泄漏呢?或者如果沒有,那怎麼可能?
具體而言,我想了解一下該memset(bmih, 0, sizeof(*bmih))
部分。 MFC在某處管理內存嗎?有人可以提供有關這方面的一些信息
void COpenCVTestView::FillBitmapInfo(BITMAPINFO* bmi, int width, int height, int bpp, int origin)
{
assert(bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32));
BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
// this part shouldn't leak?
memset(bmih, 0, sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = origin ? abs(height) : -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = (unsigned short)bpp;
bmih->biCompression = BI_RGB;
if (bpp == 8)
{
RGBQUAD* palette = bmi->bmiColors;
for (int i = 0; i < 256; i++)
{
palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
palette[i].rgbReserved = 0;
}
}
}