本文整理汇总了C++中GlobalMemoryStatus函数的典型用法代码示例。如果您正苦于以下问题:C++ GlobalMemoryStatus函数的具体用法?C++ GlobalMemoryStatus怎么用?C++ GlobalMemoryStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GlobalMemoryStatus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GlobalMemoryStatus
void CCppLanguageTester::test_cpp_alloc_physical_memory()
{
MEMORYSTATUS startMemoryStatus = {0};
MEMORYSTATUS afterNewMemoryStatus = {0};
MEMORYSTATUS afterAccessMemoryStatus = {0};
GlobalMemoryStatus(&startMemoryStatus);
//申请分配10M的内存空间
const int nAllocSize = 10 * 1024 * 1024;
BYTE *pBuff = new BYTE[ nAllocSize ];
GlobalMemoryStatus(&afterNewMemoryStatus);
ZeroMemory(pBuff, nAllocSize);
GlobalMemoryStatus(&afterAccessMemoryStatus);
delete [] pBuff;
FTLTRACE(TEXT("Memory Status: Start -> AfterNew -> AfterAccess\n")),
FTLTRACE(TEXT(" AvailPhys: %fM -> %fM -> %fM\n"),
(float)startMemoryStatus.dwAvailPhys/1024/1024,
(float)afterNewMemoryStatus.dwAvailPhys/1024/1024,
(float)afterAccessMemoryStatus.dwAvailPhys/1024/1024);
FTLTRACE(TEXT(" AvailVirtual: %fM -> %fM -> %fM\n"),
(float)startMemoryStatus.dwAvailVirtual/1024/1024,
(float)afterNewMemoryStatus.dwAvailVirtual/1024/1024,
(float)afterAccessMemoryStatus.dwAvailVirtual/1024/1024);
//调用new以后内存即会分配
CPPUNIT_ASSERT(startMemoryStatus.dwAvailPhys - afterNewMemoryStatus.dwAvailPhys >= nAllocSize);
}
示例2: modmem_memory_total
static int modmem_memory_total( INSTANCE * my, int * params )
{
#ifdef WIN32
MEMORYSTATUS mem ;
GlobalMemoryStatus( &mem ) ;
return mem.dwTotalPhys ;
#elif defined(TARGET_BEOS)
system_info info;
get_system_info( &info );
return B_PAGE_SIZE * ( info.max_pages );
#elif !defined(TARGET_MAC) && !defined(TARGET_WII)
/* Linux and other Unix (?) */
struct sysinfo meminf;
int fv;
if ( sysinfo( &meminf ) == -1 ) return -1;
if ( !( fv = kernel_version_type() ) ) return -1;
if ( fv == 1 )
return meminf.totalram * meminf.mem_unit;
else
return meminf.totalram;
return -1;
#else
return 0; //TODO
#endif
}
示例3: get_random_info
static void get_random_info(unsigned char seed[16])
{
#if defined(_XBOX)
AssertFatal(false, "get_random_info not implemented on Xbox360");
#else
MD5_CTX c;
struct {
MEMORYSTATUS m;
SYSTEM_INFO s;
FILETIME t;
LARGE_INTEGER pc;
DWORD tc;
DWORD l;
TCHAR hostname[MAX_COMPUTERNAME_LENGTH + 1];
} r;
MD5Init(&c); /* memory usage stats */
GlobalMemoryStatus(&r.m); /* random system stats */
GetSystemInfo(&r.s); /* 100ns resolution (nominally) time of day */
GetSystemTimeAsFileTime(&r.t); /* high resolution performance counter */
QueryPerformanceCounter(&r.pc); /* milliseconds since last boot */
r.tc = GetTickCount();
r.l = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerName(r.hostname, &r.l );
MD5Update(&c, (unsigned char *) &r, sizeof(r));
MD5Final(seed, &c);
#endif
}
示例4: UpdateSystemInfoP
bool UpdateSystemInfoP( FvSystemInfo &kSI )
{
if ( s_pfImportedGetSystemTimes )
{
FILETIME kIdleFileTime, kKernelFileTime, kUserFileTime;
s_pfImportedGetSystemTimes( &kIdleFileTime, &kKernelFileTime, &kUserFileTime );
FvUInt64 uiIdleTime = *(FvUInt64*)&kIdleFileTime;
FvUInt64 uiKernelTime = *(FvUInt64*)&kKernelFileTime;
FvUInt64 uiUserTime = *(FvUInt64*)&kUserFileTime;
//gCurMaxCPU = (uiKernelTime + uiKserTime) / gCPUCount;
//td.curCPU = gCurMaxCPU - uiIdleTime / gCPUCount;
}
MEMORYSTATUS kMem;
GlobalMemoryStatus( &kMem );
kSI.m_kMem.max.update(kMem.dwTotalPhys);
kSI.m_kMem.val.update(kMem.dwAvailPhys);
MIB_IPSTATS kIPStats;
GetIpStatistics( &kIPStats );
kSI.m_kPackTotOut.update(kIPStats.dwOutRequests);
kSI.m_kPackDropOut.update(kIPStats.dwOutDiscards);
kSI.m_kPackTotIn.update(kIPStats.dwInReceives);
kSI.m_kPackDropIn.update(kIPStats.dwInDiscards);
return true;
}
示例5: sizeof
void ofApp::checkMemory() {
// Check Memory
MEMORYSTATUS memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&memInfo);
// Virtual Memory
DWORDLONG totalVirtualMem = memInfo.dwTotalVirtual;
DWORDLONG totalVirtualMemMB = totalVirtualMem / DIV;
DWORDLONG virtualMemUsed = memInfo.dwTotalVirtual - memInfo.dwAvailVirtual;
DWORDLONG virtualMemUsedMB = virtualMemUsed / DIV;
cout << "Total Virtual Memory Is " << totalVirtualMemMB << " MB (" << (totalVirtualMemMB / 1000) / 1000 << " GB)." << endl;
cout << "We Are Using " << virtualMemUsedMB << " MB (" << (virtualMemUsedMB / 1000) / 1000 << " GB) Of That Amount. " << endl;
// Physical Memory
DWORDLONG totalPhysMem = memInfo.dwTotalPhys;
DWORDLONG totalPhysMemMB = totalPhysMem / DIV;
DWORDLONG physMemUsed = memInfo.dwTotalPhys - memInfo.dwAvailPhys;
DWORDLONG physMemUsedMB = physMemUsed / DIV;
cout << "Total Physical Memory Is " << totalPhysMemMB << " MB (" << (totalPhysMemMB / 1000) / 1000 << " GB)." << endl;
cout << "We Are Using " << physMemUsedMB << " MB (" << (physMemUsedMB / 1000) / 1000 << " GB) Of That Amount. " << endl;
}
示例6: noise_regular
/*
* This function is called on a timer, and it will monitor
* frequently changing quantities such as the state of physical and
* virtual memory, the state of the process's message queue, which
* window is in the foreground, which owns the clipboard, etc.
*/
void noise_regular(void)
{
HWND w;
DWORD z;
POINT pt;
MEMORYSTATUS memstat;
FILETIME times[4];
w = GetForegroundWindow();
random_add_noise(&w, sizeof(w));
w = GetCapture();
random_add_noise(&w, sizeof(w));
w = GetClipboardOwner();
random_add_noise(&w, sizeof(w));
z = GetQueueStatus(QS_ALLEVENTS);
random_add_noise(&z, sizeof(z));
GetCursorPos(&pt);
random_add_noise(&pt, sizeof(pt));
GlobalMemoryStatus(&memstat);
random_add_noise(&memstat, sizeof(memstat));
GetThreadTimes(GetCurrentThread(), times, times + 1, times + 2,
times + 3);
random_add_noise(×, sizeof(times));
GetProcessTimes(GetCurrentProcess(), times, times + 1, times + 2,
times + 3);
random_add_noise(×, sizeof(times));
}
示例7: GlobalMemoryStatus
void _MEMInfo::_UpdateMI( )
{
#ifdef WIN32
MEMORYSTATUS MS;
GlobalMemoryStatus( &MS );
m_MI.nTotalMem = MS.dwTotalPhys / 1024;
m_MI.nFreeMem = MS.dwAvailPhys / 1024;
#else
char* szfile = ftostr( "/proc/meminfo" );
char* szfind = NULL;
if( szfile )
{
szfind = strstr( szfile, "MemTotal" );
if( szfind )
sscanf( szfind, "MemTotal:\t%u kB",
&m_MI.nTotalMem );
szfind = strstr( szfile, "MemFree" );
if( szfind )
sscanf( szfind, "MemFree:\t%u kB",
&m_MI.nFreeMem );
}
#endif
}
示例8: get_random_info
void get_random_info(unsigned char seed[16])
{
MD5_CTX c;
typedef struct {
MEMORYSTATUS m;
SYSTEM_INFO s;
FILETIME t;
LARGE_INTEGER pc;
DWORD tc;
DWORD l;
char hostname[MAX_COMPUTERNAME_LENGTH + 1];
} randomness;
randomness r;
/* Initialize memory area so that valgrind does not complain */
memset(&r, 0, sizeof r);
/* memory usage stats */
GlobalMemoryStatus( &r.m );
/* random system stats */
GetSystemInfo( &r.s );
/* 100ns resolution (nominally) time of day */
GetSystemTimeAsFileTime( &r.t );
/* high resolution performance counter */
QueryPerformanceCounter( &r.pc );
/* milliseconds since last boot */
r.tc = GetTickCount();
r.l = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerName( r.hostname, &r.l );
/* MD5 it */
MD5Init(&c);
MD5Update(&c, (unsigned char *)(&r), sizeof r);
MD5Final(seed, &c);
};
示例9: guessReasonableMaxmemory
/* Make a guess for a reasonable amount of memory for the hashtable
* @return number of kilo-bytes to be used
*/
unsigned long guessReasonableMaxmemory(void)
{
unsigned long const one_kilo = 1024;
unsigned long const one_giga = 1024*1024;
unsigned long result = one_giga;
/* GlobalMemoryStatusEx() has only been available since Windows 2000
*/
#if defined(_WIN32_WINNT) && _WIN32_WINNT>=_WIN32_WINNT_WIN2K
MEMORYSTATUSEX memstatEx;
memstatEx.dwLength = sizeof memstatEx;
if (GlobalMemoryStatusEx(&memstatEx))
{
unsigned long long const available_kilos = memstatEx.ullAvailPhys/one_kilo;
/* we are really erring on the safe side here :-) */
if (available_kilos<=ULONG_MAX)
result = (unsigned long)available_kilos;
}
#else
MEMORYSTATUS memstat;
GlobalMemoryStatus(&memstat);
result = memstat.dwAvailPhys/one_kilo;
#endif
return result;
}
示例10: LockMut
bool VirtualMemoryManager::EnsureFreeMemory(size_t size)
{
if(!inited)
return false;
LockMut(vmemMutex);
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
while(ms.dwAvailPhys < size)
{
if(LOG && logging)
LOG->Trace("Freeing memory: need %i, have %i", size, ms.dwAvailPhys);
if(!DecommitLRU())
{
if(LOG)
LOG->Trace("VMem error: No pages left to free while reserving memory");
return false;
}
}
return true;
}
示例11: Sys_InitMemory
void Sys_InitMemory(void)
{
int i;
i = COM_CheckParm("-heapsize");
if (i && i < com_argc - 1)
host_parms.memsize = Q_atoi(com_argv[i + 1]) * 1024;
if (host_parms.memsize < MINIMUM_WIN_MEMORY)
{
#ifdef _WIN32
MEMORYSTATUS lpBuffer;
lpBuffer.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&lpBuffer);
if (lpBuffer.dwTotalPhys)
{
if (lpBuffer.dwTotalPhys < FIFTEEN_MB)
Sys_Error("%s: Available memory less than 15MB!!! %i", __func__, host_parms.memsize);
host_parms.memsize = (int)(lpBuffer.dwTotalPhys >> 1);
if (host_parms.memsize < MINIMUM_WIN_MEMORY)
host_parms.memsize = MINIMUM_WIN_MEMORY;
}
else
示例12: defined
bool COSOperator::getSystemMemory(irr::u32* Total, irr::u32* Avail)
{
#if defined(_IRR_WINDOWS_API_)
MEMORYSTATUS MemoryStatus;
MemoryStatus.dwLength = sizeof(MEMORYSTATUS);
// cannot fail
GlobalMemoryStatus(&MemoryStatus);
if (Total)
*Total = (irr::u32)(MemoryStatus.dwTotalPhys>>10);
if (Avail)
*Avail = (irr::u32)(MemoryStatus.dwAvailPhys>>10);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return true;
#elif defined(_IRR_POSIX_API_) // || defined(MACOSX)
long ps = sysconf(_SC_PAGESIZE);
long pp = sysconf(_SC_PHYS_PAGES);
long ap = sysconf(_SC_AVPHYS_PAGES);
if ((ps==-1)||(pp==-1)||(ap==-1))
return false;
if (Total)
*Total = ((ps*(long long)pp)>>10);
if (Avail)
*Avail = ((ps*(long long)ap)>>10);
return true;
#endif
// TODO: implement for OSX
return false;
}
示例13: Dlg_OnTimer
void Dlg_OnTimer(HWND hwnd, UINT id) {
// Initialize the structure length before calling GlobalMemoryStatus.
MEMORYSTATUS ms = { sizeof(ms) };
GlobalMemoryStatus(&ms);
TCHAR szData[512] = { 0 };
StringCchPrintf(szData, _countof(szData),
TEXT("%d\n%d\n%I64d\n%I64d\n%I64d\n%I64d\n%I64d"),
ms.dwMemoryLoad, ms.dwTotalPhys,
(__int64) ms.dwAvailPhys, (__int64) ms.dwTotalPageFile,
(__int64) ms.dwAvailPageFile, (__int64) ms.dwTotalVirtual,
(__int64) ms.dwAvailVirtual);
SetDlgItemText(hwnd, IDC_DATA, szData);
// Get the current process working set and private bytes.
PROCESS_MEMORY_COUNTERS_EX pmc = { sizeof(PROCESS_MEMORY_COUNTERS_EX) };
GetProcessMemoryInfo(GetCurrentProcess(), (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc));
StringCchPrintf(szData, _countof(szData),
TEXT("%I64d K\n%I64d K"),
(__int64) pmc.WorkingSetSize / 1024,
(__int64) pmc.PrivateUsage / 1024);
SetDlgItemText(hwnd, IDC_PROCESSDATA, szData);
}
示例14: updateMemoryStatus
void updateMemoryStatus()
{
//メモリの使用状況を更新する
static Uint32 m_uMemoryUse = 1;
static Uint32 m_uMemoryMaxUse = 1;
static Uint32 m_uMemoryTotal = 0;
MEMORYSTATUS memory;
memory.dwLength = sizeof( MEMORYSTATUS );
GlobalMemoryStatus( &memory );
if( m_uMemoryTotal == 0 )
{
//ゲームで使用可能なメモリ量を計測
m_uMemoryTotal = memory.dwAvailPhys;
m_uMemoryTotal = memory.dwAvailVirtual;
}
//現在ゲームが使用しているメモリ量
m_uMemoryUse = m_uMemoryTotal - memory.dwAvailPhys;
m_uMemoryUse = m_uMemoryTotal - memory.dwAvailVirtual;
//最大風速
if( m_uMemoryUse > m_uMemoryMaxUse ) m_uMemoryMaxUse = m_uMemoryUse;
CGameGirl::GetInstance()->ReportMemoryStatus( m_uMemoryUse , m_uMemoryTotal , m_uMemoryMaxUse );
}
示例15: GlobalMemoryStatus
/*
* int sysinfo(struct sysinfo *info)
*/
void SysCalls::sys_sysinfo(CONTEXT& ctx)
{
linux::sysinfo si;
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
memset(&si, 0, sizeof(si));
si.uptime = GetTickCount()/1000;
si.loads[0] = 0; //1, 5, and 15 minute load averages
si.loads[1] = 0;
si.loads[2] = 0;
si.totalram = ms.dwAvailPhys;
si.freeram = ms.dwTotalPhys;
si.sharedram = 0;/* Amount of shared memory */
si.bufferram = 0; /* Memory used by buffers */
si.totalswap = ms.dwTotalPageFile;
si.freeswap = ms.dwAvailPageFile;
si.procs = g_pKernelTable->m_Processes.size();
si.totalhigh = 0; /* Total high memory size */
si.freehigh = 0; /* Available high memory size */
si.mem_unit = 4096; //same as page size???
P->WriteMemory((ADDR)ctx.Ebx, sizeof(si), &si);
ctx.Eax = 0;
}