Commit 7793791d authored by sumpfralle's avatar sumpfralle

reduce memory consumption of stored toolpaths to 1/3 (applies only to python 2.6 or above)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@270 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 8b9cf6bd
""" the points of a path are only used for describing coordinates. Thus we
don't really need complete "Point" instances that consume a lot of memory.
Since python 2.6 the "namedtuple" factory is available.
This reduces the memory consumption of a toolpath down to 1/3.
"""
try:
# this works for python 2.6 or above (saves memory)
from collections import namedtuple
tuple_point = collections.namedtuple("TuplePoint", "x y z")
get_point_object = lambda point: tuple_point(point.x, point.y, point.z)
except ImportError:
# dummy for python < v2.6 (consumes more memory)
get_point_object = lambda point: point
class Path: class Path:
id = 0 id = 0
...@@ -22,7 +36,7 @@ class Path: ...@@ -22,7 +36,7 @@ class Path:
return s return s
def append(self, p): def append(self, p):
self.points.append(p) self.points.append(get_point_object(p))
def reverse(self): def reverse(self):
self.points.reverse() self.points.reverse()
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