-#include "stdafx.h"\r
-\r
-#include "os/windows/windows.h"\r
-\r
-#include <unordered_map>\r
-#include <tbb/mutex.h>\r
-#include <tbb/atomic.h>\r
-\r
-namespace caspar { namespace detail {\r
- \r
-tbb::mutex g_mutex;\r
-std::unordered_map<void*, size_t> g_map;\r
-size_t g_free;\r
-\r
-void allocate_store(size_t size)\r
-{ \r
- SIZE_T workingSetMinSize = 0, workingSetMaxSize = 0;\r
- if(::GetProcessWorkingSetSize(::GetCurrentProcess(), &workingSetMinSize, &workingSetMaxSize))\r
- { \r
- workingSetMinSize += size;\r
- workingSetMaxSize += size;\r
-\r
- if(!::SetProcessWorkingSetSize(::GetCurrentProcess(), workingSetMinSize, workingSetMaxSize)) \r
- throw std::bad_alloc(); \r
-\r
- g_free += size;\r
- }\r
-}\r
-\r
-void* alloc_page_locked(size_t size)\r
-{\r
- tbb::mutex::scoped_lock lock(g_mutex);\r
-\r
- if(g_free < size)\r
- allocate_store(size);\r
-\r
- auto p = ::VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);\r
- if(!p)\r
- throw std::bad_alloc();\r
-\r
- if(::VirtualLock(p, size) == 0) \r
- {\r
- ::VirtualFree(p, 0, MEM_RELEASE);\r
- throw std::bad_alloc();\r
- }\r
- \r
- g_free -= size;\r
- g_map[p] = size;\r
- return p;\r
-\r
-}\r
-\r
-void free_page_locked(void* p)\r
-{ \r
- tbb::mutex::scoped_lock lock(g_mutex);\r
-\r
- if(g_map.find(p) == g_map.end())\r
- return;\r
-\r
- ::VirtualFree(p, 0, MEM_RELEASE);\r
-\r
- g_free += g_map[p];\r
- g_map.erase(p);\r
-}\r
-\r
+#include "stdafx.h"
+
+#include "os/windows/windows.h"
+
+#include <unordered_map>
+#include <tbb/mutex.h>
+#include <tbb/atomic.h>
+
+namespace caspar { namespace detail {
+
+tbb::mutex g_mutex;
+std::unordered_map<void*, size_t> g_map;
+size_t g_free;
+
+void allocate_store(size_t size)
+{
+ SIZE_T workingSetMinSize = 0, workingSetMaxSize = 0;
+ if(::GetProcessWorkingSetSize(::GetCurrentProcess(), &workingSetMinSize, &workingSetMaxSize))
+ {
+ workingSetMinSize += size;
+ workingSetMaxSize += size;
+
+ if(!::SetProcessWorkingSetSize(::GetCurrentProcess(), workingSetMinSize, workingSetMaxSize))
+ throw std::bad_alloc();
+
+ g_free += size;
+ }
+}
+
+void* alloc_page_locked(size_t size)
+{
+ tbb::mutex::scoped_lock lock(g_mutex);
+
+ if(g_free < size)
+ allocate_store(size);
+
+ auto p = ::VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+ if(!p)
+ throw std::bad_alloc();
+
+ if(::VirtualLock(p, size) == 0)
+ {
+ ::VirtualFree(p, 0, MEM_RELEASE);
+ throw std::bad_alloc();
+ }
+
+ g_free -= size;
+ g_map[p] = size;
+ return p;
+
+}
+
+void free_page_locked(void* p)
+{
+ tbb::mutex::scoped_lock lock(g_mutex);
+
+ if(g_map.find(p) == g_map.end())
+ return;
+
+ ::VirtualFree(p, 0, MEM_RELEASE);
+
+ g_free += g_map[p];
+ g_map.erase(p);
+}
+
}}
\ No newline at end of file