Alternate e697dbe9c5997e35395fe158628dd8c5209481da
for Visual Studio 2022 and Windows 11.
全て クラス 名前空間 ファイル 関数 変数 型定義 列挙型 列挙値 マクロ定義 ページ
HeapPerformanceCheck.cpp
[詳解]
1
5
6#include "pch.h"
8
9using namespace PerfCheck;
10
12 :PerformanceCheck (console)
13{
14}
15
17{
18}
19
21{
22 return this->Core (0);
23}
24
25BOOL HeapPerformanceCheck::Core (const int param1)
26{
28
29 auto threadFunc = [](LPVOID lpvParam)->DWORD
30 {
31 BOOL ret;
33
34 alt::HeapMemory memory;
35 ret = memory.Create ();
36 if (!ret) return -1;
37
38 alt::Event event;
39 int loop = me->_loop;
40
41 event.Open (_T ("START_EVENT"));
42 event.Wait ();
43
44 OutputDebugString (_T ("Thread action is started.\n"));
45 do
46 {
47 int index = rand () % 10;
48 TCHAR tsz[10];
49 wsprintf (tsz, _T ("%d(%d),"), GetCurrentThreadId (), index);
50 OutputDebugString (tsz);
51
52 LPVOID lpvMem = memory.Allocate (me->_allocSize[index]);
53 ZeroMemory (lpvMem, me->_allocSize[index]);
54
55 ret = memory.Free (lpvMem);
56
57 } while (--loop);
58 OutputDebugString (_T ("Thread action is stopped.\n"));
59
60 return 0;
61 };
62
63 alt::Event event;
64 event.Create (_T ("START_EVENT"), TRUE, FALSE);
65 _console.Write (_T ("Event作成\n"));
66
67 const int numOfThreads = 48;
68 this->_loop = 50000;
69
70 alt::Thread thread[numOfThreads];
71 for (auto& item : thread)
72 {
73 item.Create (threadFunc, (LPVOID)this);
74 SwitchToThread ();
75 }
76 _console.Write (_T ("Thread作成\n"));
77
78 HANDLE threadHandles[numOfThreads];
79 for (int i = 0; i < numOfThreads; i++)
80 {
81 threadHandles[i] = thread[i].GetHandle ();
82 }
83 _console.Write (_T ("Thread Handle収集\n"));
84
85 _console.Write (_T ("計測開始\n"));
86 Q.Start ();
87
88 event.Set ();
89 WaitForMultipleObjects (numOfThreads, threadHandles, TRUE, INFINITE);
90
91 Q.Stop ();
92 _console.Write (_T ("計測終了\n"));
93
94 int msec = static_cast<int>(Q.PastTime ());
95
96 _console.Format( _T ("It takes %dmsec.\n"), msec);
97
98 return TRUE;
99}
HeapMemoryクラス性能測定用
#define loop
プリコンパイル済みヘッダー ファイルです。
HeapMemoryクラス性能測定用
virtual BOOL DoAction()
処理開始
HeapPerformanceCheck(alt::Console &console)
virtual BOOL Core(const int param1)
コンソールに関するクラス
Definition: Console.h:88
DWORD APIENTRY Write(LPCTSTR lpctszString) const
コンソールに文字を出力します。
Definition: Console.cpp:54
VOID APIENTRY Format(LPCTSTR format,...) const
コンソールに文字を出力します。
Definition: Console.cpp:63
イベントに関するWindowsAPIを集約したクラス
Definition: Event.h:16
BOOL APIENTRY Create(LPCTSTR lpctszName, BOOL bManualReset, BOOL bInitialState)
イベントを作成します。
Definition: Event.cpp:12
HANDLE APIENTRY GetHandle() const
継承先はこの関数でハンドルを取得します。
ヒープメモリに関するAPIを集約したクラス
Definition: HeapMemory.h:46
virtual BOOL APIENTRY Free(LPVOID lpvMem)
メモリの返却
Definition: HeapMemory.cpp:130
virtual LPVOID APIENTRY Allocate(SIZE_T bytes, DWORD dwFlags=MEM_ZERO)
メモリの取得
Definition: HeapMemory.cpp:115
BOOL APIENTRY Create(SIZE_T initialSize=0, SIZE_T maximumSize=0, DWORD dwOptions=0)
ヒープ領域の取得
Definition: HeapMemory.cpp:56
高分解能時間計測クラス
VOID APIENTRY Start()
計測を開始します。
double APIENTRY PastTime() const
計測開始〜計測終了までの時間を出力します。
VOID APIENTRY Stop()
計測を終了します。
スレッドに関するWindowsAPIを集約したクラス
Definition: Thread.h:43
BOOL APIENTRY Create(PTHREAD_START_ROUTINE function=NULL, LPVOID lpvParam=NULL, DWORD dwCreationFlag=0)
スレッドを作成します。
Definition: Thread.cpp:24