What is the most efficient way to represent small values in a struct?

前端 未结 15 848
星月不相逢
星月不相逢 2021-02-01 02:15

Often I find myself having to represent a structure that consists of very small values. For example, Foo has 4 values, a, b, c, d that, range from

15条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 02:37

    First, precisely define what you mean by "most efficient". Best memory utilization? Best performance?

    Then implement your algorithm both ways and actually profile it on the actual hardware you intend to run it on under the actual conditions you intend to run it under once it's delivered.

    Pick the one that better meets your original definition of "most efficient".

    Anything else is just a guess. Whatever you choose will probably work fine, but without actually measuring the difference under the exact conditions you'd use the software, you'll never know which implementation would be "more efficient".

提交回复
热议问题