| 289 | }; |
| 290 | |
| 291 | class TMappedAllocation: TMoveOnly { |
| 292 | public: |
| 293 | TMappedAllocation(size_t size = 0, bool shared = false, void* addr = nullptr); |
| 294 | ~TMappedAllocation() { |
| 295 | Dealloc(); |
| 296 | } |
| 297 | TMappedAllocation(TMappedAllocation&& other) noexcept { |
| 298 | this->swap(other); |
| 299 | } |
| 300 | TMappedAllocation& operator=(TMappedAllocation&& other) noexcept { |
| 301 | this->swap(other); |
| 302 | return *this; |
| 303 | } |
| 304 | void* Alloc(size_t size, void* addr = nullptr); |
| 305 | void Dealloc(); |
| 306 | void* Ptr() const { |
| 307 | return Ptr_; |
| 308 | } |
| 309 | char* Data(ui32 pos = 0) const { |
| 310 | return (char*)(Ptr_ ? ((char*)Ptr_ + pos) : nullptr); |
| 311 | } |
| 312 | char* Begin() const noexcept { |
| 313 | return (char*)Ptr(); |
| 314 | } |
| 315 | char* End() const noexcept { |
| 316 | return Begin() + MappedSize(); |
| 317 | } |
| 318 | size_t MappedSize() const { |
| 319 | return Size_; |
| 320 | } |
| 321 | void swap(TMappedAllocation& with) noexcept; |
| 322 | |
| 323 | private: |
| 324 | void* Ptr_ = nullptr; |
| 325 | size_t Size_ = 0; |
| 326 | bool Shared_ = false; |
| 327 | #ifdef _win_ |
| 328 | void* Mapping_ = nullptr; |
| 329 | #endif |
| 330 | }; |
| 331 | |
| 332 | template <class T> |
| 333 | class TMappedArray: private TMappedAllocation { |