Difference between
modified post 1cfcc5 by Anonymous on Wed 3rd Jul 2024 00:56
original post 26a740 by Anonymous on Wed 3rd Jul 2024 00:19
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | ||
| 2 | 2 | /* | |
| 3 | 3 | * Compile and run with | |
| 4 | 4 | * rm -f a.exe* ; clang++ -target x86_64-w64-mingw32 -std=c++17 -Bstatic c++pmr1.cpp | |
| 5 | 5 | * $ PATH+=':/usr/x86_64-w64-mingw32/sys-root/mingw/bin/' ./a.exe | |
| 6 | 6 | */ | |
| 7 | 7 | #include <array> | |
| 8 | 8 | #include <cstddef> | |
| 9 | 9 | #include <iostream> | |
| 10 | 10 | #include <memory_resource> | |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | int main(int ac, char *av[]) | |
| 14 | 14 | { | |
| 15 | - | constexpr int total_mem{8192}; | |
| 15 | + | char buffer[64]; | |
| 16 | 16 | ||
| 17 | - | std::array<std::byte, total_mem> buf; | |
| 17 | + | std::pmr::monotonic_buffer_resource pool{buffer, sizeof(buffer)}; | |
| 18 | + | std::pmr::polymorphic_allocator<char> pa{&pool}; | |
| 18 | 20 | ||
| 19 | - | std::pmr::monotonic_buffer_resource pool{buf.data(), buf.size()}; | |
| 21 | + | for (int i=0 ; i < 10 ; i++) { | |
| 20 | - | std::pmr::string s{"x", &pool}; | |
| 22 | + | s+=s; | |
| 23 | + | } | |
| 21 | 24 | ||
| 25 | + | std::cout << s << std::endl; |
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
rovema.kpaste.net RSS