summaryrefslogtreecommitdiffstats
path: root/util/memory/mmapalloc.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/memory/mmapalloc.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/memory/mmapalloc.cpp')
-rw-r--r--util/memory/mmapalloc.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/util/memory/mmapalloc.cpp b/util/memory/mmapalloc.cpp
new file mode 100644
index 00000000000..ec618cc8084
--- /dev/null
+++ b/util/memory/mmapalloc.cpp
@@ -0,0 +1,33 @@
+#include "alloc.h"
+#include "mmapalloc.h"
+
+#include <util/system/filemap.h>
+#include <util/generic/singleton.h>
+
+namespace {
+ class TMmapAllocator: public IAllocator {
+ public:
+ TBlock Allocate(size_t len) override {
+ TMappedAllocation m(len + sizeof(TMappedAllocation));
+ TMappedAllocation* real = (TMappedAllocation*)m.Data();
+
+ (new (real) TMappedAllocation(0))->swap(m);
+
+ TBlock ret = {real + 1, len};
+
+ return ret;
+ }
+
+ void Release(const TBlock& block) override {
+ TMappedAllocation tmp(0);
+ TMappedAllocation* real = ((TMappedAllocation*)block.Data) - 1;
+
+ real->swap(tmp);
+ real->~TMappedAllocation();
+ }
+ };
+}
+
+IAllocator* MmapAllocator() {
+ return SingletonWithPriority<TMmapAllocator, 0>();
+}