dynamic memory allocation
This commit is contained in:
parent
69115c0c22
commit
aec373abe8
1 changed files with 13 additions and 12 deletions
23
src/lib.rs
23
src/lib.rs
|
|
@ -112,6 +112,11 @@ impl GeometryData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dynamically resize the struct in memory to accomodate the index
|
||||||
|
if index >= self.triangles.len() {
|
||||||
|
self.triangles.resize(index + 1, TriangleData::default());
|
||||||
|
}
|
||||||
|
|
||||||
if types == 0 || types == 2 {
|
if types == 0 || types == 2 {
|
||||||
self.triangles[index] = TriangleData {
|
self.triangles[index] = TriangleData {
|
||||||
index,
|
index,
|
||||||
|
|
@ -197,21 +202,17 @@ impl Xenobalanus {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn preprocess(&mut self, types: usize) {
|
pub fn preprocess(&mut self, types: usize) {
|
||||||
|
let geometry_data = Arc::new(Mutex::new(GeometryData::new()));
|
||||||
let num_triangles = self.triangulation.len() / 3;
|
|
||||||
|
|
||||||
// Initialize GeometryData with the correct size for triangles vector
|
|
||||||
let mut initial_geometry_data = GeometryData::new();
|
|
||||||
initial_geometry_data.triangles.resize(num_triangles, TriangleData::default());
|
|
||||||
|
|
||||||
let geometry_data = Arc::new(Mutex::new(initial_geometry_data));
|
|
||||||
|
|
||||||
self.triangulation.par_chunks(3).enumerate().for_each(|(index, tri_idx)| {
|
self.triangulation.par_chunks(3).enumerate().for_each(|(index, tri_idx)| {
|
||||||
let gd = geometry_data.clone(); // Clone Arc for use in each thread
|
let gd = geometry_data.clone(); // Clone Arc for use in each thread, not the data itself
|
||||||
gd.lock().unwrap().add_triangle(index, &self.points, tri_idx, types);
|
|
||||||
|
// Perform locked update
|
||||||
|
let mut gd_lock = gd.lock().unwrap();
|
||||||
|
gd_lock.add_triangle(index, &self.points, tri_idx, types);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.geometry_data = Arc::try_unwrap(geometry_data).unwrap().into_inner().unwrap()
|
self.geometry_data = Arc::try_unwrap(geometry_data).unwrap().into_inner().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delfin(
|
pub fn delfin(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue