创建日志文件win 32 [英] creating log file win 32
本文介绍了创建日志文件win 32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void dshowCapture::initlogfile()
{
/////////log file initialization////
TCHAR dwDirectory[256];
TCHAR capturelogfile[256];
ZeroMemory(dwDirectory, sizeof(dwDirectory));
ZeroMemory(capturelogfile, sizeof(capturelogfile));
GetCurrentDirectory(256, dwDirectory);
strcpy (capturelogfile,dwDirectory);
strcat(capturelogfile,"\\CaptureLog.txt");
std::ofstream *fs;
fs=new std::ofstream(capturelogfile);
char *log="helow";
for(int i=0;i<1000;i++)
fs->write(log,sizeof(log));
fs->close();
delete fs;
}
这是正确的实现,因为程序运行但在
之后
Is this correct implementation because program runs but after
std::ofstream *fs;
fs=new std::ofstream(capturelogfile);
大约48个字节,在执行for循环后增加50个字节
删除操作后,内存保持增加的值(大约100字节左右).
near about 48 bytes and after execution of for loop 50 bytes increase
after delete operation memory remains to that increased value(near abt 100 bytes)
推荐答案
虽然我对代码有很多注释,例如制作TCHAR数组和使用strcpy代替_tcscpy或更好的_tcscpy_s,但显然您可以编写指针的大小(好东西,您在此不使用64位)大小写)到文件;我无法直接看到内存泄漏的出现.
请注意,如果您的应用程序泄漏,则在关闭应用程序时,很可能会在输出窗口中看到正在转储正常阻止"通知.
干杯,
AT.
Hi,
Though I have a number of comments to the code like making TCHAR arrays and using strcpy in stead of _tcscpy or bettery yet _tcscpy_s and apparently you are ok wiht writing the size of a pointer (good thing you''re not using 64 bits in this case) to the file; I can''t directly see a memory leak appearing.
Note that if your app is leaking you will most likely see a "dumping normal block" notification in the output window when closing the app.
Cheers,
AT.
这篇关于创建日志文件win 32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文