File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
test/problems/hellounix/submissions/run_time_error Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,19 @@ using namespace std;
13
13
14
14
const size_t inc_mb = 128 ;
15
15
16
+ template <typename T>
17
+ T use (std::vector<T>& todo) {
18
+ if (todo.empty ()) return {};
19
+ volatile T* p = &todo[0 ];
20
+ // reading a volatile pointer is a side effect and cannot be optimized
21
+ return p[0 ];
22
+ }
23
+
16
24
int main () {
17
25
vector<vector<char >> vs;
18
26
while (true ) {
19
27
vs.emplace_back (inc_mb * 1024 * 1024 );
20
- std::cerr << " Allocated: " << inc_mb * vs.size () << " MB" << std::endl;
28
+ std::cerr << " Allocated: " << inc_mb * vs.size () << " MB ( " << use (vs. back ()) << " ) " << std::endl;
21
29
}
22
30
return 0 ;
23
31
}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ const size_t mb = 513;
16
16
template <typename T>
17
17
T use (std::vector<T>& todo) {
18
18
if (todo.empty ()) return {};
19
- volatile T* p = &to_use [0 ];
19
+ volatile T* p = &todo [0 ];
20
20
// reading a volatile pointer is a side effect and cannot be optimized
21
21
return p[0 ];
22
22
}
You can’t perform that action at this time.
0 commit comments