Skip to content

Commit

Permalink
Don't repeately retrieve handle to process heap
Browse files Browse the repository at this point in the history
  • Loading branch information
mqudsi committed Mar 11, 2020
1 parent a6cbe81 commit 0a07451
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions paste/paste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// The maximum number of chars to buffer before issuing a write
#define MAX_BUF 1024

HANDLE _processHeap;

enum class ExitReason : int
{
Success,
Expand All @@ -23,13 +25,13 @@ template<typename T>
T* _malloc(DWORD count)
{
DWORD bytes = sizeof(T) * count;
return (T*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bytes);
return (T*)HeapAlloc(_processHeap, HEAP_ZERO_MEMORY, bytes);
}

template<typename T>
void _free(T *obj)
{
HeapFree(GetProcessHeap(), 0, obj);
HeapFree(_processHeap, 0, obj);
}

int WINAPI CtrlHandler(DWORD ctrlType) {
Expand Down Expand Up @@ -128,6 +130,7 @@ void print(const WCHAR *text, LineEnding lineEnding)

int wmain(void)
{
_processHeap = GetProcessHeap();
SetConsoleCtrlHandler(CtrlHandler, true);

int argc;
Expand Down

0 comments on commit 0a07451

Please sign in to comment.