pavel-kirienko / o1heap

Constant-complexity deterministic memory allocator (heap) for hard real-time high-integrity embedded systems. There is very little activity because the project is finished and does not require further changes.
MIT License
251 stars 28 forks source link

Experiment: replace the standard heap in NuttX with O1Heap #1

Open pavel-kirienko opened 4 years ago

pavel-kirienko commented 4 years ago

Stock NuttX seems to be using a standard O(n) best-fit list-traversal allocator. It should be trivial to replace and benchmark.

nacansino commented 4 years ago

Regarding using O1Heap with NuttX, I tried allocating a memory arena for use with O1Heap on a dynamically allocated C++ wrapper class (with new) on a PX4 fmuv3 build.

The compiler then throws an error upon instantiating the class about alignment. (Note that this should just be a warning but it seems that the PX4 build demands that all warnings be turned into errors.

error:

error: ‘new’ of type ‘UAVCAN’ with extended alignment 16 [-Waligned-new=]

Code

private:

    static size_t constexpr HEAP_SIZE = 4096;

    uint8_t _base[HEAP_SIZE] __attribute__ ((aligned (O1HEAP_ALIGNMENT)));

Setting the alignment to 8 suppresses the warning, but as per O1Heap specifications, the heap must be aligned at the value specified on the O1HEAP_ALIGNMENT definition.

Is this a known issue?

pavel-kirienko commented 4 years ago

It's not an issue. The compiler is merely telling you that O1HEAP_ALIGNMENT > alignof(std::max_align_t), where O1HEAP_ALIGNMENT = 16 and alignof(std::max_align_t) = 8, which is natural for many 32-bit platforms. You should relax the alignment requirement on your type to avoid this diagnostic; at any rate, it is not related to O1Heap in any way.