Skip to content
/ rstd Public

Reasonable/Robust/Rapid single header C++ Standard Library Replacement

License

Notifications You must be signed in to change notification settings

Czapa10/rstd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rstd
Reasonable/Robust/Rapid
C++ Standard Library Replacement

General info

I don't like API of the default C++ standard library and the way its containers and other things allocate memory is too slow for my gamedev purposes. So I decided to create my own replacement for it. The library is quite early in development so I wouldn't recommend you to use it just yet. It is sort of a side project for me and I make it along with my main, video game project. I add things here when I need them in my game.

The library uses c++20 features and as far as I know compiles only on MSVC.

Features

For now library supports only windows !!!

Library has a couple of containers to offer:

  • string<size, character>
  • array<type, size>
  • pushable_array<type, size>
  • doubly_linked_list<type>, doubly_linked_list_with_counter<type>
  • singly_linked_list<type>, singly_linked_list_with_counter<type>
  • backward_singly_linked_list<type>, backward_singly_linked_list_with_counter<type>

Arena

Arena allocator (also called push allocator) in this library is the basic allocator on which doubly_linked_list, singly_linked_list, backward_singly_linked_list (and their versions with counters) base their memory allocation. You have to assign arena to those containers before you use them, which is a little bit of pain in the ass, but in reward you gain a lot of performance and control.
You have to assign arena to container by using OwnArena(arena&) or ShareArena(arena&). Both of them return arena_ref which can be passed to constructors of these containers.
OwnArena() copies arena to container.
ShareArena() passes pointer to the arena to container so the same arena can be used outside of this container. It could be shared by multiple containers.

rstd::arena Arena = rstd::AllocateArenaZero(10_MB);
auto S = rstd::PushStructZero(Arena, some_struct);
rstd::doubly_linked_list<some_struct> List = rstd::OwnArena(rstd::SubArena(Arena, 1_MB));
rstd::singly_linked_list<some_struct> List2 = rstd::ShareArena(Arena);

Thread pool

File io

Time utilities

Simple random number generator

String parsing utilities

Optional

String view

Defer

You can wrap your code in rstd_defer function macro and it will execute at the end of scope.

{
auto File = rstd::OpenFile("file.txt", rstd::io_mode::Write);
rstd_defer(rstd::Close(File));

// writing to file
  
// file is closed here
}

And other utilities

Compilation

Rstd is a single header library.
Copy rstd.h file to your project directory or to whatever directory you like.
And then define rstd_Implementation in only one of C++ files that include this header.
You also have to define rstd_Debug before including rstd.h (in all files)
Define rstd_Debug to 1 if you want to have assertions and debug only code turn on
Define rstd_Debug to 0 to turn off assertions and to make release only code be compiled

a.cpp

#define rstd_Implementation
#define rstd_Debug 1
#include "rstd.h"

b.cpp

#define rstd_Debug 1
#include "rstd.h"

c.cpp

#define rstd_Debug 1
#include "rstd.h"

You can modify rstd.h and define rstd_Debug there so you don't have to do it every time you include rstd.h.
You could also create my_rstd.h file which sets up rstd configuration macros and then includes rstd.h.

About

Reasonable/Robust/Rapid single header C++ Standard Library Replacement

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages