Why keep constant array sizes?

In b2Shape, there is an array of vertices, which are part of that shape. Why not change it to a pointer, and when the shape is created, allocate an array, only big enough to hold the number of vertices that are in it?

For example:
b2Vec2 m_vertices[b2_maxPolygonVertices];

Would go to:
b2Vec2* m_vertices;

And then, when the shape is created from a shape def:
m_vertices = new b2Vec2[m_vertexCount];

This would save memory, and put virtually no restriction on the number of vertices. 🙂
I remember trying to increase to 16 but
caused an assert. Thanks to Erin changing something 🙂 It now works with 16 but I think that
might be the max.
Mike
I try to avoid lots of heap allocations (new & malloc) in Box2D because this can lead to fragmentation and eventually degrade performance.

That said, I should probably use the small block allocator for vertices. Allocations in the shape definition should be handled by a growable array.

I'll put this on the TODO list.

Original thread: https://box2d.org/forum/viewtopic.php?t=231