Suggestion to correct an old design issue in SDL 2.0

Dear SDL developers,

since SDL 2.0 is not meant to be 100% backwards compatible, it’s
probably worth to think about changing a little software design issue:

The function SDL_CreateRGBSurface always clears the created surface,
which is conceptually similar to malloc() always clearing the allocated
memory. This is of course sub-optimal in terms of performance, since
memory needs to be swapped in without need (if only part of the surface
is initially used by the application), and the entire clearing procedure
is often not needed anyway (if the application just copies something there).

In my very performance critical SDL, I removed these lines from
SDL_surface.c:

     /* This is important for bitmaps */
     SDL_memset(surface->pixels, 0, surface->h * surface->pitch);

Best regards,
Elmar

I’d have to disagree.? 15 years ago this might have been an issue, but memsets are incredibly fast on modern hardware, and the correctness benefits of zeroing out the memory are clearly worth the negligible performance hit, since the user will not always fill the entire area right away, as you acknowledge.? Well-defined behavior is always preferable to undefined behavior when you’re trying to build a reliable program, and this provides well-defined behavior.

Unless you have profiling results demonstrating that the memset causes a non-trivial bottleneck in performance, you should really just leave it as it is.

Mason________________________________
From: Elmar Krieger
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Sunday, September 30, 2012 9:56 AM
Subject: [SDL] Suggestion to correct an old design issue in SDL 2.0

Dear SDL developers,

since SDL 2.0 is not meant to be 100% backwards compatible, it’s probably worth to think about changing a little software design issue:

The function SDL_CreateRGBSurface always clears the created surface, which is conceptually similar to malloc() always clearing the allocated memory. This is of course sub-optimal in terms of performance, since memory needs to be swapped in without need (if only part of the surface is initially used by the application), and the entire clearing procedure is often not needed anyway (if the application just copies something there).

In my very performance critical SDL, I removed these lines from SDL_surface.c:

? ? ? ? /* This is important for bitmaps */
? ? ? ? SDL_memset(surface->pixels, 0, surface->h * surface->pitch);

Best regards,
Elmar


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org