Skip to content

Commit 97f0b1f

Browse files
authored
fix: add proof for the std::pmr::vector that it only use the stack space buffer instead of heap (#77)
1 parent 5a5f787 commit 97f0b1f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

documents/vol3-standard-library/13-custom-allocators.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ int main()
201201
v.push_back(i);
202202
}
203203
std::cout << "v.size() = " << v.size() << "\n";
204+
std::cout << "v.data() address = " << std::hex << v.data() << "\n";
205+
std::cout << "The range of stack buffer is [" << std::hex << (void *)buffer << "," << (void *)buffer+sizeof(buffer) << "]\n";
204206
std::cout << "vector 的内存来自栈上 buffer,零全局堆分配\n";
205207
return 0;
206208
}
@@ -212,6 +214,8 @@ g++ -std=c++20 -O2 -o /tmp/pmr_test /tmp/pmr_test.cpp && /tmp/pmr_test
212214

213215
```text
214216
v.size() = 100
217+
v.data() address = 0x7fff4f3c2fdc
218+
The range of stack buffer is [0x7fff4f3c2de0,0x7fff4f3c3de0]
215219
vector 的内存来自栈上 buffer,零全局堆分配
216220
```
217221

0 commit comments

Comments
 (0)