File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
test/problems/hellounix/submissions/run_time_error Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -13,9 +13,26 @@ using namespace std;
13
13
14
14
const size_t mb = 513 ;
15
15
16
+ template <typename T>
17
+ T use (std::vector<T>& todo) {
18
+ // init with some data
19
+ for (std::size_t i = 0 ; i < todo.size (); i++) todo[i] = T (i % 7 );
20
+ // do some computation that needs the memory
21
+ for (int k = 0 ; k < 7 ; k++) {
22
+ for (std::size_t i = 0 ; i < todo.size (); i++) {
23
+ std::size_t j = (i + todo[i]) % todo.size ();
24
+ todo[j] = (todo[i] % 7 ) + (todo[j] % 7 );
25
+ }
26
+ }
27
+ // accumulate the result
28
+ T res = 0 ;
29
+ for (auto x : todo) res = (res >> 1 ) + (x >> 1 );
30
+ return res;
31
+ }
32
+
16
33
int main () {
17
- std::cerr << " Trying to allocate at least: " << 513 << " MB" << std::endl;
18
- vector<char > v (513 * 1024 * 1024 );
19
- std::cerr << " Allocated: " << (v. end () - v. begin ()) << " MB " << std::endl;
34
+ std::cerr << " Trying to allocate at least: " << mb << " MB" << std::endl;
35
+ vector<char > v (mb * 1024 * 1024 );
36
+ std::cerr << " Allocated: " << mb << " MB ( " << use (v) << " ) " << std::endl;
20
37
return 0 ;
21
38
}
You can’t perform that action at this time.
0 commit comments