9#include "locked_memory_allocator_intf.hpp"
10#include "../telemetry/telemetry.hpp"
11#include "../char_maps/char_maps.hpp"
12#include "../utility/utility.hpp"
13#include "../macros.hpp"
23hi_export_module(hikogui.memory.locked_memory_allocator : impl);
25hi_export
namespace hi::inline
v1 {
27[[nodiscard]]
inline std::byte *locked_memory_allocator_allocate(
std::size_t n)
noexcept
29 auto p = VirtualAlloc(NULL, n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
34 auto handle = GetCurrentProcess();
35 SIZE_T minimum_working_set_size;
36 SIZE_T maximum_working_set_size;
38 if (!GetProcessWorkingSetSize(handle, &minimum_working_set_size, &maximum_working_set_size)) {
42 minimum_working_set_size +=
ceil(n, SIZE_T{4096});
43 maximum_working_set_size +=
ceil(n, SIZE_T{4096});
44 if (!SetProcessWorkingSetSize(handle, minimum_working_set_size, maximum_working_set_size)) {
46 "Could not set process working set size to {}:{}. '{}'",
47 minimum_working_set_size,
48 maximum_working_set_size,
52 if (!VirtualLock(p, n)) {
57 return static_cast<std::byte *
>(p);
60inline void locked_memory_allocator_deallocate(std::byte *p,
std::size_t n)
noexcept
62 if (not VirtualUnlock(p, n)) {
66 auto handle = GetCurrentProcess();
67 SIZE_T minimum_working_set_size;
68 SIZE_T maximum_working_set_size;
70 if (!GetProcessWorkingSetSize(handle, &minimum_working_set_size, &maximum_working_set_size)) {
74 minimum_working_set_size -=
ceil(n, SIZE_T{4096});
75 maximum_working_set_size -=
ceil(n, SIZE_T{4096});
76 if (!SetProcessWorkingSetSize(handle, minimum_working_set_size, maximum_working_set_size)) {
78 "Could not set process working set size to {}:{}. '{}'",
79 minimum_working_set_size,
80 maximum_working_set_size,
86 if (not VirtualFree(p, 0, MEM_RELEASE)) {
Rules for working with win32 headers.
hi_export std::string get_last_error_message()
Get the OS error message from the last error received on this thread.
Definition exception_win32_impl.hpp:30
DOXYGEN BUG.
Definition algorithm_misc.hpp:20