-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrabmem.rs
36 lines (31 loc) · 958 Bytes
/
grabmem.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//we'll figure out cli parsing later but its 'extern crate getopts;
extern crate getopts;
use getopts::Options;
use std::{env, time};
fn usage( ){
println!("usage: grabmem max rate step");
println!("this program allocates memory in RATE second intervals, increasing by STEP megabytes of memory, untill memory reaches MAX.\n");
}
fn grab(size: i64) {
myMemory = size; //will this get optimized away if we never use it?
memsize += size;
println!("holding {} memory", memsize);
}
fn main(){
let arg: Vec<String> = env::args().collect();
usage();
const max = &arg[1];
const rate = &arg[2];
const step = &arg[3].parse::<i64>();
let duration = time::Duration::from_secs(rate);
let mut memsize = 0i64 ;
let mut myMemory = [i64;step] ;
loop {
if memsize >= max {
println!("hit max memory");
break;
}
grab(step);
thread::sleep(duration);
}
}