0

hope you'll help me to understand. I have a class, that defines a buffer:

typedef std::variant<signed char, unsigned char, short, unsigned short, int, unsigned int, float> BufferData;

struct BufferAttribute {
  unsigned int index;
  int size = 4;
  char format = ATTRIBUTE_FORMAT::FLOAT;
  bool normalized = false;
  int stride = 0;
  int offset = 0;
  std::vector<BufferData> data;
  std::string name;
};

As you can see, I have a char that defines a format, so in the future, I will know the exact data format. But as for the data, I'm using a variant which makes me worry about the performance of the visitor. What type can I use to make it faster or better? Or do you think that Variant is a good choice?


P.S. I worrying about processing thousands of numbers from this buffer in real-time in my game app.

1 Answers1

2

If you are concerned about performance, you have to measure it in your use case. General statements wrt. performance tend to be wrong or may out date with the next compiler version and or hardware generation.

Here the general performance of std::variant has been analyzed.

If this is applicable to you is in question. You have to make sure that the ´std::variant´ in BufferAttribute actually is your hotspot. You can find the hotspots using a tool such as perf or vTune.

schorsch312
  • 5,553
  • 5
  • 28
  • 57