Use pointers to variable members instead of dynamic ones. Sketch in this gist: https://gist.github.com/eruffaldi/5070833dbf23f9f843b6859b266b7a4f