Giter Site home page Giter Site logo

rstd's Introduction

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.

rstd's People

Contributors

czapa10 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.