You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Hi. short_alloc is really just a demo. arena<N, alignment>::deallocate has been optimized for stack-order deallocation. You can make that arbitrarily more complex (and expensive) to suit whatever your application needs. If you make it sufficiently general purpose, you will have re-implemented malloc/free, and will have likely lost any benefit of a custom allocator.
Hi Howard, thanks for the great implementation of
short_alloc
. I tried to use it forstd::list
orstd::set,
and am running into an issue where the behavior of underline container is different when using theshort_alloc
. So if I callclear()
on a std::list which usesshort_alloc
, it only deallocates the last element in the buffer. But in standardstd::list
with the default allocator, it deallocates/releases all memory. I imagine same behavior is expected when calling clear() for theshort_alloc
(e.g., resetting the arena). So, let's say I have a capacity of 10 element in std::list withshort_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 ofstd::list
and it tries to get a copy of the allocator and calls deallocate on all elements. But it seems like when the allocator isshort_alloc
, the loop covers only last element's removal.The text was updated successfully, but these errors were encountered: