Memset with stride

1.8k Views Asked by At

With OpenGL, there's a lot of times where putting strides on the data is necessary for better efficiency. for example, the memory structure would be vertex-color-normal-vertex-color-normal.. etc.

Is there any viable option for changing, say, only the color section of a memory with some kind of memset variant (that is, not using a loop).

Also brings to question, is there such thing as a looping memset? For example, in an array of colors made of four floats each, set all of them to a particular color.

2

There are 2 best solutions below

3
On BEST ANSWER

Just use a loop. There is nothing magical about memset, internally it is just using a loop, it may on same compilers be slightly optimized to clear 64bits at a time if used with 0, but it doesn't set a block of memory in a single instruction

1
On

I would just go with a loop. memset() does some neat little optimizations to write multiple bytes per iteration, so you might look at how memset() itself is working and see if those kinds of optimizations apply to your code. But in the end, it's just a loop.

Here is the memset() source code - pretty readable, though you'll have to dig up all of the typedefs and macros to see exactly how the optimization is happening.