Skip to content

Commit

Permalink
free temporary vectors earlier (#1047)
Browse files Browse the repository at this point in the history
* free temporary vectors earlier

* clear some more

doesn't seem very effective though
  • Loading branch information
pca006132 authored Nov 16, 2024
1 parent ee32b30 commit d9bc83a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/boolean3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ Boolean3::Boolean3(const Manifold::Impl &inP, const Manifold::Impl &inQ,
Intersect12(inQ, inP, s20, p2q0, s11, p1q1, z20, xyzz11, p2q1_, false);
PRINT("x21 size = " << x21_.size());

s11.clear();
xyzz11.clear();
z02.clear();
z20.clear();

Vec<int> p0 = p0q2.Copy(false);
p0q2.Resize(0);
Vec<int> q0 = p2q0.Copy(true);
Expand Down
22 changes: 22 additions & 0 deletions src/boolean_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,12 +778,18 @@ Manifold::Impl Boolean3::Result(OpType op) const {
AddNewEdgeVerts(edgesP, edgesNew, p1q2_, i12, v12R, inP_.halfedge_, true);
AddNewEdgeVerts(edgesQ, edgesNew, p2q1_, i21, v21R, inQ_.halfedge_, false);

v12R.clear();
v21R.clear();

// Level 4
Vec<int> faceEdge;
Vec<int> facePQ2R;
std::tie(faceEdge, facePQ2R) =
SizeOutput(outR, inP_, inQ_, i03, i30, i12, i21, p1q2_, p2q1_, invertQ);

i12.clear();
i21.clear();

// This gets incremented for each halfedge that's added to a face so that the
// next one knows where to slot in.
Vec<int> facePtrR = faceEdge;
Expand All @@ -799,14 +805,28 @@ Manifold::Impl Boolean3::Result(OpType op) const {
AppendPartialEdges(outR, wholeHalfedgeQ, facePtrR, edgesQ, halfedgeRef, inQ_,
i30, vQ2R, facePQ2R.begin() + inP_.NumTri(), false);

edgesP.clear();
edgesQ.clear();

AppendNewEdges(outR, facePtrR, edgesNew, halfedgeRef, facePQ2R,
inP_.NumTri());

edgesNew.clear();

AppendWholeEdges(outR, facePtrR, halfedgeRef, inP_, wholeHalfedgeP, i03, vP2R,
facePQ2R.cview(0, inP_.NumTri()), true);
AppendWholeEdges(outR, facePtrR, halfedgeRef, inQ_, wholeHalfedgeQ, i30, vQ2R,
facePQ2R.cview(inP_.NumTri(), inQ_.NumTri()), false);

wholeHalfedgeP.clear();
wholeHalfedgeQ.clear();
facePtrR.clear();
facePQ2R.clear();
i03.clear();
i30.clear();
vP2R.clear();
vQ2R.clear();

#ifdef MANIFOLD_DEBUG
assemble.Stop();
Timer triangulate;
Expand All @@ -819,6 +839,8 @@ Manifold::Impl Boolean3::Result(OpType op) const {
DEBUG_ASSERT(outR.IsManifold(), logicErr, "polygon mesh is not manifold!");

outR.Face2Tri(faceEdge, halfedgeRef);
halfedgeRef.clear();
faceEdge.clear();

#ifdef MANIFOLD_DEBUG
triangulate.Stop();
Expand Down

0 comments on commit d9bc83a

Please sign in to comment.