?? checkmemory.cpp
字號:
#include "stdafx.h"
#include <Windows.h>
MEMORYSTATUS gSystem_Memory_Start;
MEMORYSTATUS gSystem_Memory_End;
void CheckMemoryDriffInit(void)
{
GlobalMemoryStatus(&gSystem_Memory_Start);
}
CString CheckMemoryDriff(void)
{
CString nstr;
long nAvailPhys;
long nAvailVirtual;
GlobalMemoryStatus(&gSystem_Memory_End);// memory status structure
nAvailPhys = gSystem_Memory_End.dwAvailPhys;
nAvailPhys -= gSystem_Memory_Start.dwAvailPhys;
nAvailVirtual = gSystem_Memory_End.dwAvailVirtual;
nAvailVirtual -= gSystem_Memory_Start.dwAvailVirtual;
/*
nstr.Format(_T("物理內(nèi)存剩余容量差 = %d Byte = %d KB = %d MB\n虛擬內(nèi)存剩余容量差 = %d Byte = %d KB = %d MB\n"),
nAvailPhys,
nAvailPhys/1024,
nAvailPhys/1024/1024,
nAvailVirtual,
nAvailVirtual/1024,
nAvailVirtual/1024/1024);
//AfxMessageBox(nstr);
*/
nstr.Format(_T("%d KB = %d MB Sys=%d KB = %d MB"),nAvailPhys/1024,nAvailPhys/1024/1024,gSystem_Memory_End.dwAvailPhys/1024,gSystem_Memory_End.dwAvailPhys/1024/1024);
return nstr;
}
#if 0
MEMORYSTATUS gSystem_Memory_Start;
MEMORYSTATUS gSystem_Memory_End;
int gSystem_Memory_Flag=0;
void CheckMemoryDriff(void)
{
CString nstr;
long nAvailPhys;
long nAvailVirtual;
if(0==gSystem_Memory_Flag)
{
GlobalMemoryStatus(&gSystem_Memory_Start);
gSystem_Memory_Flag = 1;
}
GlobalMemoryStatus(&gSystem_Memory_End);// memory status structure
nAvailPhys = gSystem_Memory_End.dwAvailPhys;
nAvailPhys -= gSystem_Memory_Start.dwAvailPhys;
nAvailVirtual = gSystem_Memory_End.dwAvailVirtual;
nAvailVirtual -= gSystem_Memory_Start.dwAvailVirtual;
nstr.Format(_T("物理內(nèi)存剩余容量差 = %d Byte = %d KB = %d MB\n虛擬內(nèi)存剩余容量差 = %d Byte = %d KB = %d MB\n"),
nAvailPhys,
nAvailPhys/1024,
nAvailPhys/1024/1024,
nAvailVirtual,
nAvailVirtual/1024,
nAvailVirtual/1024/1024);
AfxMessageBox(nstr);
}
#endif
#if 0
DWORD ntime = GetTickCount();
file.WritePrivateProfileString(_T("BookList1"),_T("MyBook1"),_T("navylau111"),_T("\\NAND\\test1.ini"));
/*
file.WritePrivateProfileString(_T("BookList1"),_T("MyBook1"),_T("navylau1"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList2"),_T("MyBook1"),_T("navylau2"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList3"),_T("MyBook1"),_T("navylau3"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList4"),_T("MyBook1"),_T("navylau4"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList5"),_T("MyBook1"),_T("navylau5"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList6"),_T("MyBook1"),_T("navylau6"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList7"),_T("MyBook1"),_T("navylau7"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList8"),_T("MyBook1"),_T("navylau8"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList9"),_T("MyBook1"),_T("navylau9"),_T("\\NAND\\test1.ini"));
file.WritePrivateProfileString(_T("BookList10"),_T("MyBook1"),_T("navylau10"),_T("\\NAND\\test1.ini"));
*/
ntime = GetTickCount()-ntime;
cstr.Format(_T("%d"),ntime);
MessageBox(cstr);
ntime = GetTickCount();
file.GetPrivateProfileString(_T("BookList"),_T("MyBook1"),_T(""), nReadBuffer[0], 20, _T("\\NAND\\test1.ini"));
ntime = GetTickCount()-ntime;
cstr.Format(_T("%d"),ntime);
MessageBox(cstr);
/*
file.GetPrivateProfileString(_T("BookList1"),_T("MyBook1"),_T(""), nReadBuffer[1], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList2"),_T("MyBook1"),_T(""), nReadBuffer[2], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList3"),_T("MyBook1"),_T(""), nReadBuffer[3], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList4"),_T("MyBook1"),_T(""), nReadBuffer[4], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList5"),_T("MyBook1"),_T(""), nReadBuffer[5], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList6"),_T("MyBook1"),_T(""), nReadBuffer[6], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList7"),_T("MyBook1"),_T(""), nReadBuffer[7], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList8"),_T("MyBook1"),_T(""), nReadBuffer[8], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList9"),_T("MyBook1"),_T(""), nReadBuffer[9], 20, _T("\\NAND\\test1.ini"));
file.GetPrivateProfileString(_T("BookList10"),_T("MyBook1"),_T(""), nReadBuffer[10], 20, _T("\\NAND\\test1.ini"));
*/
#endif
#if 0
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpDefault, // default string
LPTSTR lpReturnedString, // destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // initialization file name
)
{
CFile nFile;
FILE *npFile;
DWORD nFileLength;
LPTSTR npFileBuffer=NULL;
DWORD nFileBufferSize;
LPTSTR npLineBuffer=NULL;
TCHAR *npf;
CString nFileStr;
DWORD nFileStrSize;
CString nStr;
//CString nStr_Old;
BOOL nbResult;
int nIndex;
int nSectionStart_Index;
int nSectionEnd_Index;
int nAppNameStart_Index;
int nAppNameEnd_Index;
int nEqualMark_Index;
int nKeyNameStart_Index;
int nKeyNameEnd_Index;
int nStringStart_Index;
int nStringEnd_Index;
int nAppName_Length;
int nKeyName_Length;
int nString_Length;
DWORD nReturnValue;
//DWORD ntime = GetTickCount();
nbResult = nFile.Open(lpFileName,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite,NULL);//若文件不存在,則創(chuàng)建一個新文件
if(!nbResult)
{
//AfxMessageBox(_T("access file fail!"));
goto EXIT_FALSE;
}
nFileLength = nFile.GetLength();
nFileBufferSize = nFileLength + APPNAME_MAXLENGTH+KEYNAME_MAXLENGTH+STRING_MAXLENGTH+10;
if(nFileBufferSize>FILE_MAXBYTES) //限制最大文件
{
//AfxMessageBox(_T("file too large!"));
nFile.Close();
goto EXIT_FALSE;
}
nFile.Close();
npFileBuffer = new TCHAR [nFileBufferSize];//characters
if(NULL==npFileBuffer)
{
//AfxMessageBox(_T("not enough memory for npFileBuffer!"));
goto EXIT_FALSE;
}
memset(npFileBuffer,0,nFileBufferSize*2);
npLineBuffer = new TCHAR [LINEBUFFER_MAXLENGTH];
if(NULL==npLineBuffer)
{
//AfxMessageBox(_T("not enough memory for npLineBuffer!"));
goto EXIT_FALSE;
}
memset(npLineBuffer,0,LINEBUFFER_MAXLENGTH*2);
if((npFile = _tfopen(lpFileName, _T("rt"))) == NULL)
{
//AfxMessageBox(_T("can not open the file!"));
goto EXIT_FALSE;
}
//while(!feof(npFile))
while(1)
{
npf=_fgetts(npLineBuffer,LINEBUFFER_MAXLENGTH,npFile);
if(npf==NULL) break;
_tcscat(npFileBuffer,npLineBuffer);
}
fclose(npFile);
nFileStr.Format(_T("%s"),npFileBuffer);
nFileStrSize = nFileStr.GetLength();//real amount of file characters
nStr.Format(_T("[%s]"),lpAppName);
nSectionStart_Index = nFileStr.Find(nStr);//搜索段名
if(-1==nAppNameStart_Index)
{//沒有搜索到段名
goto EXIT_FALSE;
}
nStr.Format(_T("\n["));
nSectionEnd_Index = nFileStr.Find(nStr,nAppNameStart_Index+2+nAppName_Length);//搜索下一個段名位置
if(-1==nSectionEnd_Index)
{//所搜索的段名處在文件的最末尾
nSectionEnd_Index = nFileStrSize -1;
}
nStr.Format(_T("\n%s"),lpKeyName);
nIndex = nFileStr.Find(nStr,nSectionStart_Index+2);
if( (-1==nKeyNameStart_Index)||(nKeyNameStart_Index>nAppNameEnd_Index))
{//搜索到段名,但沒有搜索到鍵名
goto EXIT_FALSE;
}
nKeyNameStart_Index++;
nStringEnd_Index = nFileStr.Find(_T('\n'),nKeyNameStart_Index);
if(-1 == nStringEnd_Index)
{//在鍵名這一行上,沒有找到回車符
nStringEnd_Index = nSectionEnd_Index;
}
nEqualMark_Index = nFileStr.Find(_T('='),nKeyNameStart_Index);
if((-1 == nEqualMark_Index)||(nEqualMark_Index>nStringEnd_Index))
{//在鍵名這一行上,沒有找到等號,則默認(rèn)該鍵無鍵值
goto EXIT_FALSE;
}
nIndex = nEqualMark_Index+1;
while(nIndex <= nStringEnd_Index)
{
if(npFileBuffer[nIndex] != _T(' ')) break;
nIndex ++;
}
if(nIndex>nStringEnd_Index) goto EXIT_FALSE;//找不到內(nèi)容
if(_T('\n')==npFileBuffer[nIndex]) goto EXIT_FALSE;//只找到回車符
nStringStart_Index = nIndex;
if(nStringEnd_Index-nStringStart_Index+1>nSize)
{
_tcsncpy(lpReturnedString,npFileBuffer+nStringStart_Index,nSize-1);
lpReturnedString[nSize-1]=_T('\0');
nReturnValue= nSize-1;
}
else
{
_tcsncpy(lpReturnedString,npFileBuffer+nStringStart_Index,nStringEnd_Index-nStringStart_Index);
lpReturnedString[nStringEnd_Index-nStringStart_Index]=_T('\0');
nReturnValue = nStringEnd_Index-nStringStart_Index;
}
EXIT_TRUE:
if(NULL!=npFileBuffer)
{
delete [] npFileBuffer;
npFileBuffer = NULL;
}
if(NULL!=npLineBuffer)
{
delete [] npLineBuffer;
npLineBuffer = NULL;
}
//ntime = GetTickCount() - ntime;
//nStr.Format(_T("time cost = %d\n"),ntime);
//AfxMessageBox(nStr);
return nReturnValue;
EXIT_FALSE:
if(NULL!=npFileBuffer)
{
delete [] npFileBuffer;
npFileBuffer = NULL;
}
if(NULL!=npLineBuffer)
{
delete [] npLineBuffer;
npLineBuffer = NULL;
}
nStr.Format(_T("%s"),lpDefault);
nReturnValue=nStr.GetLength();
if(nReturnValue+1>nSize)
{
_tcsncpy(lpReturnedString,lpDefault,nSize-1);
lpReturnedString[nSize-1]=_T('\0');
return (DWORD)(nSize-1);
}
else
{
_tcscpy(lpReturnedString,lpDefault);
return nReturnValue;
}
};
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -