Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior: do not release the last segment. #18

Open
angainor opened this issue May 18, 2021 · 1 comment
Open

Behavior: do not release the last segment. #18

angainor opened this issue May 18, 2021 · 1 comment

Comments

@angainor
Copy link
Collaborator

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
Copy link
Collaborator

boeschf commented Jun 14, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants