Skip to content

Behavior: do not release the last segment. #18

@angainor

Description

@angainor

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);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions