ホーム » VC » MemStat.hxx

2012年7月
1234567
891011121314
15161718192021
22232425262728
293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,048 アクセス



MemStat.hxx

Xcode や VC , W Mobile で可能な様にコードを書いてみた.


#ifndef MemStat_hxx
#define MemStat_hxx
//
#ifdef _WIN32
  typedef __int64 i64 ;
  typedef unsigned __int64 ui64 ;
#else
  typedef long long i64 ;
  typedef unsigned long long ui64 ;
#endif
//
#ifdef __APPLE_CC__
  #include <mach/mach.h>
#endif
#ifdef _WIN32
  #include <Windows.h>
  #include <WinBase.h>
#endif
//
class MemoryStatus {
public:

} ;
//

{
  P_Free = P_Total = 0 ;
  #ifdef __APPLE_CC__
  {
    unsigned int count = 0 ;
    mach_port_t host_port = ::mach_host_self() ;
    host_basic_info_data_t hb_info;
    {
      count = HOST_BASIC_INFO_COUNT ;
      ::host_info(host_port,HOST_BASIC_INFO,(host_info_t)&hb_info,&count) ;
      }
    vm_statistics_data_t vm_info;
    {
      count = HOST_VM_INFO_COUNT;
      ::host_statistics(host_port,HOST_VM_INFO,(host_info_t)&vm_info,&count) ;
      }
    P_Free = vm_info.free_count * vm_page_size ;
    P_Total = hb_info.max_mem ;
    }
  #endif
  #ifdef _WIN32
  #if !defined(_WIN32_WCE) && (_MFC_VER >= 0x700)
  {
    MEMORYSTATUSEX memStat ;
    memset(&memStat,0,sizeof(MEMORYSTATUSEX)) ;
    memStat.dwLength= sizeof(MEMORYSTATUSEX) ;
    ::GlobalMemoryStatusEx(&memStat) ;
    P_Free = memStat.ullAvailPhys ;
    P_Total = memStat.ullTotalPhys ;
    }
  #else
  {
    MEMORYSTATUS memStat ;
    memset(&memStat,0,sizeof(MEMORYSTATUS)) ;
    memStat.dwLength= sizeof(MEMORYSTATUS) ;
    ::GlobalMemoryStatus(&memStat) ;
    P_Free = memStat.dwAvailPhys ;
    P_Total = memStat.dwTotalPhys ;
    }
  #endif
  #endif
  }
//
#endif


ファイルは,UTF-8 と言うか,シフトJIS の設定で,7 bit の範囲の文字のみ使用.
改行は,CR+LF としている.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

1件のコメント

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。