Storage of vertexes and planes in cpPolyShape
Posted: Sun Jul 07, 2013 10:14 am
I guess this is a question/suggestion for the authors of Chipmunk or someone in the know of its implementation.
I noticed that upon creation of a cpPolyShape the verts and splitting planes are copied onto 2 newly allocated chunks of memory in setUpVerts. Why not put them in one chunk of mem?
I even thought of putting them in a variable length array in cpPolyShape but I then cpPolyShapeSetVerts would realloc the shape and thus could change the pointer, which can mess up things.
I don't expect it to make performance soar, but saving a malloc per shape on setup, some saved memory due to less fragmentation, and possibly a tiny improvement in read access times due to reduced cache thrashing may be worthwhile...
I noticed that upon creation of a cpPolyShape the verts and splitting planes are copied onto 2 newly allocated chunks of memory in setUpVerts. Why not put them in one chunk of mem?
I even thought of putting them in a variable length array in cpPolyShape but I then cpPolyShapeSetVerts would realloc the shape and thus could change the pointer, which can mess up things.
I don't expect it to make performance soar, but saving a malloc per shape on setup, some saved memory due to less fragmentation, and possibly a tiny improvement in read access times due to reduced cache thrashing may be worthwhile...