Commit 4990eb42 authored by Guillaume Seguin's avatar Guillaume Seguin

Try reducing peak memory usage

parent 83c49a7b
...@@ -406,15 +406,18 @@ class GcodeModel(Model): ...@@ -406,15 +406,18 @@ class GcodeModel(Model):
twopi = 2 * math.pi twopi = 2 * math.pi
processed_lines = 0
while layer_idx < len(model_data.all_layers): while layer_idx < len(model_data.all_layers):
with self.lock: with self.lock:
nlines = len(model_data) nlines = len(model_data)
ntravelcoords = travel_coords_count(nlines) remaining_lines = nlines - processed_lines
ncoords = coords_count(nlines) # Only reallocate memory which might be needed, not memory
nindices = indices_count(nlines) # for everything
# TODO: only reallocate memory if needed ntravelcoords = coords_count(remaining_lines) + travel_vertex_k
# compute ncoords(nlines-lines_processed)+vertex_k ncoords = coords_count(remaining_lines) + vertex_k
if ncoords != vertices.size: nindices = indices_count(remaining_lines) + index_k
if ncoords > vertices.size:
self.travels.resize(ntravelcoords, refcheck = False) self.travels.resize(ntravelcoords, refcheck = False)
self.vertices.resize(ncoords, refcheck = False) self.vertices.resize(ncoords, refcheck = False)
self.colors.resize(ncoords, refcheck = False) self.colors.resize(ncoords, refcheck = False)
...@@ -614,6 +617,8 @@ class GcodeModel(Model): ...@@ -614,6 +617,8 @@ class GcodeModel(Model):
self.initialized = False self.initialized = False
self.loaded = True self.loaded = True
processed_lines += len(layer)
if callback: if callback:
callback(layer_idx + 1) callback(layer_idx + 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment