Giter Club home page Giter Club logo

static-stl's Introduction

Static Standard Template Library (SSTL) Build Status Build Status

What is SSTL?

The SSTL is a partial reimplementation of the C++ Standard Template Library (STL) that strictly avoids the use of dynamic memory allocation.

Motivation

Although very handy, dynamic memory allocation is for many developers an unaffordable luxury. In fact, the use of dynamic memory allocation implies drawbacks such as:

  • indeterministic behavior (in terms of latencies)
  • synchronization costs in a multithreaded environmnent
  • additional memory requirements (heap bookkeeping + fragmentation)
  • worse locality of reference

There are applications in which such additional costs cannot be accepted. An example is the embedded world, where systems are often constrained to run with very limited memory resources. Other examples are the fields of finance, gaming, etc. where the introduced indeterminism/latencies might just be too high.

Features

  • Static reimplementations of STL abstractions:
    • std::function
    • std::vector
    • std::deque
    • std::stack
    • std::queue
    • std::priority_queue
    • bitmap allocator
    • free-list allocator
  • No RTTI used.
  • No exceptions required (however all the components are exception safe).
  • No virtual functions used (except for sstl::function's type erasure, of course).
  • No runtime check overheads (only customizable assertions).
  • C++11 compatible.
  • Header-only library.
  • Tested with clang 3.7, gcc 5 and MSVC 1800 (Visual Studio 2013).

TODO list

  • std::shared_ptr
  • std::unordered_set
  • std::unordered_map

Example

For example, the SSTL provides a reimplementation of std::vector that can be used as follows:

constexpr size_t MAX_ELEMENTS = 10;
sstl::vector<int, MAX_ELEMENTS> vec{};
sstl::vector<int>& ref = vec;
ref.push_back(0);

The elements are stored into an internal buffer whose capacity is specified by the extra template argument. Note that this template argument is required only for the creation of the container. The created instance can then be used and passed around as a reference to a capacity-agnostic type (e.g. sstl::vector<int>).

How was SSTL born?

I used to make a living from programming CPU-intensive algorithms on an embedded system with quite tight memory constraints. In that system I couldn't have a heap, since it would have required some extra memory that I couldn't afford. As a consequence I couldn't use many of the much-loved STL components, since they heavily rely on dynamic memory allocations. To make up for this lack of abstractions I started to reimplement some STL components.

static-stl's People

Contributors

0xc0170 avatar gatorque avatar jwellbelove avatar rukkal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

static-stl's Issues

Support for unordered_map

I see you were planning on implementing unordered_map, and have a TODO. Any chance that you've written it, or do you have a timeline of when you might get that finished?

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.