I’m currently developing a project with SDL. It basically draws and moves images (surfaces) on the screen.
To move an image without leaving a trail, you must first clear the screen surface, pretty much like glClear(), and I’m currently doing it with a simple for loop iterating over the surface’s pixels (also drawing a black box on the surface or memset).
While the previous solutions work fine for small surfaces, they get increasingly slower as the surface grows bigger so i was looking for the fastest way I could clear (zero) a memory block.
Also, a friend pointed out that using SIMD instructions could do the work really fast but the last time I’ve done ASM was on a 8085, any insight on this could also be useful.
The fastest way is to use
memset.This automatically uses SIMD on architectures that support it*. You are not going to beat it. It is already memory bound, so it’s writing zeroes as fast as the processor can spit them out. I don’t know who told you that
memsetis slower for larger blocks, but you should stop listening to that person.*There are some toolchains that don’t give you a fast
memset. It is unlikely that you are using one.