Memset with stride

北城以北 提交于 2020-01-06 13:11:07

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5138084/memset-with-stride

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!