May 2018
Intermediate to advanced
462 pages
11h 5m
English
Rust is now aware of the C functions, and we have our internal structs reworked to use C layout: it is time to link up the C functions that manipulate mars_t with our Mars. Because we're sharing ownership of Mars between the Rust allocator and the C allocator, we've got to be careful to initialize the Mars struct with null pointers in the fields that C will own, like so:
impl MarsBuilder { pub fn freeze(self) -> Mars { let mut mars = Mars { n_warriors: 2, cycles: u32::from(self.cycles.unwrap_or(10_000)), core_size: self.core_size.unwrap_or(8_000), processes: self.processes.unwrap_or(10_000), max_warrior_length: self.max_warrior_length.unwrap_or(100), war_tab: ptr::null_mut(), core_mem: ptr::null_mut(), queue_mem: ...Read now
Unlock full access