ghex-org / hwmalloc

Other
0 stars 3 forks source link

Behavior: do not release the last segment. #18

Open angainor opened 3 years ago

angainor commented 3 years ago

I suggest the last segment in the pool is kept and not freed when empty. Since the segment will only be allocated when the user actually first allocates something, this will not result in useless RAM usage, and will make sure that the future allocations are faster in an allocate-free code scenario. Otherwise you have to specify m_never_free, which is a bit harsh: we'd like to keep the heaps under control and optimize the performance.

    void free(block_type const& b)
    {
    b.m_segment->free(b);
        if (!m_never_free && b.m_segment->is_empty())
        {
            std::lock_guard<std::mutex> lock(m_mutex);

            // THIS IS THE CHANGE
            if (b.m_segment->is_empty() && m_segments.size()>1) m_segments.erase(b.m_segment);
        }
    }
boeschf commented 3 years ago

I think that's a good idea - we can even make this configurable later, but for now, i think the default of having one segment always like you suggest is good.