Memory usage in SDL_LockTexture

I’m wondering about high memory usage when I call SDL_LockTexture. I have a window that is 1024x576, and a streaming texture that is 256x144. When I just call SDL_RenderCopy and SDL_RenderPresent, my app uses 130MB. If i call SDL_LockTexture/SDL_UnlockTexture each frame, my app uses 259MB. Is this typical? Here is all I’m doing, as you can see I’m not even updating the texture yet:

void* pixels;
int pitch;
if (!SDL_LockTexture(render_texture, NULL, &pixels, &pitch))

SDL_RenderCopy(renderer, render_texture, NULL, NULL);

I’m using SDL 2.28.3 on Windows 11.

It just seems like a lot of memory to me. I know it’s not really in the big picture. The real issue is that I actually have 6 different windows (for debugging) that I also do this with, and my memory usage jumps up to 1.8GB. Now those windows won’t be in the release build. I guess I just wanted to know if I’m doing things wrong.

Sorry for the bump if that’s against the forum rules. I would just really like to know if I’m doing this incorrectly.

SDL_LockTexture() winds up doing at least 1 allocation somewhere, whether by SDL itself or by the GPU driver, because it has to create space for the memory returned in the pixels variable. There may be intermediary allocations made by the GPU driver as well.

As long as memory usage isn’t continually climbing then it’s probably fine.

1 Like

Thanks for the reply. Memory usage is stable. I’ll not worry about it then :slight_smile: