-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REFACT] Use custom buffer to store thread info
- Loading branch information
1 parent
75b3bc5
commit f9e1571
Showing
3 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
#include <windows.h> | ||
|
||
namespace pesieve { | ||
namespace util { | ||
|
||
struct AutoBuffer | ||
{ | ||
AutoBuffer() : buf(nullptr), max_size(0), buf_size(0) { } | ||
|
||
~AutoBuffer() { | ||
if (buf) { | ||
::free(buf); | ||
buf = nullptr; | ||
} | ||
max_size = 0; | ||
buf_size = 0; | ||
} | ||
|
||
BYTE* alloc(size_t _buf_size) | ||
{ | ||
if (_buf_size > max_size) { | ||
BYTE* allocated = (BYTE*)::realloc((void*)buf, _buf_size); | ||
if (!allocated) { | ||
return nullptr; | ||
} | ||
buf = allocated; | ||
max_size = _buf_size; | ||
} | ||
buf_size = _buf_size; | ||
::memset(buf, 0, max_size); | ||
return buf; | ||
} | ||
|
||
BYTE* buf; | ||
size_t max_size; | ||
size_t buf_size; | ||
}; | ||
|
||
}; //namespace util | ||
}; //namespace pesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters