Hydrosphere icon indicating copy to clipboard operation
Hydrosphere copied to clipboard

Add memory allocator and a subset of smart pointers

Open vbe0201 opened this issue 6 years ago • 1 comments

Summary

As discussed on Discord, this Pull Request mainly adds a memory allocator which is capable of mapping and managing a given memory region and implementations for shared_ptr and unqiue_ptr.

I also made the fix_codestyle script executable under Linux and reformatted everything with Clang-Format.

Goals

  • Adequate replacement for std::shared_ptr and std::unqiue_ptr.

  • Free of dependencies.

  • Lightweight implementation.

  • Clean and fast code.

  • Good documentation for Doxygen.

Limitations

  • Neither the memory allocator nor the smart pointers can be considered thread-safe.

    • Can be resolved by using a hs::os::Mutex.
  • No support for heap allocations.

  • No implementation of weak_ptr as I didn't consider it necessary.

    • If there's a demand, I can add it.
  • Only a subset of the smart pointers is actually implemented.

    • The implementations can be extended if necessary.

vbe0201 avatar Sep 14 '19 12:09 vbe0201

For reference:

We now have a shared_ptr/unique_ptr implementation that differ from the std counterpart. This is mainly because we don't follow the allocator_traits requirements.

I also rewrote the memory allocator to use a simple free list (this still uses a first fit algorithm but I guess it's clearly enough for now).

The doc still need to be updated and some small optimization can be done on the free list fragmentation.

Kaenbyo avatar Sep 15 '19 11:09 Kaenbyo