Vai al contenuto

Memory Safety

Questo contenuto non è ancora disponibile nella tua lingua.

Memory safety is a core concern in Saturn. C++ gives us unmatched control and performance, but with power comes responsibility. By following clear principles and using available tooling, we can write safe, maintainable, and performant code.


Manual memory management is strongly discouraged wherever possible. Instead, Saturn relies on:

  • Custom allocators: Inspired by Zig-style memory management, these provide deterministic and controlled memory usage while maintaining high performance.
  • RAII-based wrappers: All C-style resources are wrapped in RAII classes to ensure proper acquisition and release. This prevents leaks, double frees, and dangling resources.

Following these principles ensures that the codebase minimizes undefined behavior while preserving the flexibility required for a high-performance engine.


Saturn integrates robust memory diagnostic tools. Its CMakePresets.json includes profiles for MSVC and Clang Address Sanitizers, enabling memory-safe builds with minimal setup.

We recommend running sanitizer-enabled builds whenever working with manual memory management, complex object hierarchies, or new subsystems. These checks guarantee that:

  • All destructors are properly virtualized and overridden.
  • No leaks, use-after-free, or dangling references exist.
  • Ownership rules are consistently followed across the codebase.

  • Prefer smart pointers (std::unique_ptr, std::shared_ptr) for dynamic allocations.
  • Use custom allocators for large pools or high-performance object sets.
  • Wrap C-style resources (file handles, GPU buffers, sockets) in RAII classes immediately upon acquisition.
  • Run Address Sanitizer builds regularly, not just for occasional checks.

By combining preventive design with diagnostic tooling, Saturn achieves a high standard of memory safety without compromising C++’s performance and flexibility.