I have this Zig code that only creates a blank window, and it consumes 46MiB of RAM. Is there anything I can do to reduce the memory usage? And, why does it use so much memory? I’m on Linux, btw.
How do you measure memory usage? What is expected memory usage?
Memory usage may depend on display diver used, display server (xorg/wayland), build of SDL (optimization level, etc.). I don’t think that 46MiB of memory is “high usage” on modern Linux systems. If you want to dig in this, check out massif tool from Valgrind.
With the default build options, I get similar results in my C++ builds. In heaptrack I saw 13 to 15 MB.
On my task manager these same programs show as about 23 to 25 MB, and 60MB if using ‘top’ in linux.
Most of this RAM use is because of allocations in libgallium, which is basically your mesa drivers.
You can remove access to those GPU drivers from your SDL3 projects on linux. I did this and those test programs now use between 400KB and 1.1MB in heaptrack.
To build SDL3 without vulkan or opengl, in a new build folder inside of SDL3’s source directory use the following:
cmake .. -DSDL_RENDER_VULKAN=OFF -DSDL_VULKAN=OFF -DSDL_OPENGL=OFF -DSDL_OPENGLES=OFF
make
sudo make install
My assumption is that without vulkan or opengl, SDL jumps to using software rendering, which runs on the CPU. Textures with scaling/rotation still work, but other things may break without the mesa drivers.
Things I noticed with just a bit of testing are; VSync is broken so you have to use SDL_Delay, and shaped windows are out.
It’s not a great solution unless you’re on an embedded system where RAM matters that much, but it’s an option. Even on an old raspberry pi 2 system, I don’t see this being a great game-changer. RAM is just too readily available, and dropping GPU access is a big ask.
For testing purposes, it would probably be a good idea to install the newly built SDL3 libs directly into your project files rather than system wide so that it doesn’t affect all of your projects.
Edit: I forgot that you are using zig, I don’t know what you might need to use for zig to do the above, only that if it’s an option in C/C++, there’s probably an equivalent for zig.