Skip to content

short_alloc behavior upon calling clear()  #11

@milad-khaledyan

Description

@milad-khaledyan

Hi Howard, thanks for the great implementation of short_alloc. I tried to use it for std::list or std::set, and am running into an issue where the behavior of underline container is different when using the short_alloc. So if I call clear() on a std::list which uses short_alloc, it only deallocates the last element in the buffer. But in standard std::list with the default allocator, it deallocates/releases all memory. I imagine same behavior is expected when calling clear() for the short_alloc (e.g., resetting the arena). So, let's say I have a capacity of 10 element in std::list with short_alloc. I push 10 elements and all goes on stack. When I call clear, I expect the arena deallocate all these 10 elements and if I push back 10 more elements, no overflow should happen, but with the current implementation, this is not happening and only the last element in arena is reset. Any idea on how to add this capability? A similar behavior happens when calling erase.

P.S., I looked at clear() implementation of std::list and it tries to get a copy of the allocator and calls deallocate on all elements. But it seems like when the allocator is short_alloc, the loop covers only last element's removal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions