https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64128
Bug ID: 64128 Summary: Let vector take advantage of malloc_usable_size for malloc-using allocators Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc-bugzilla at contacts dot eelis.net Created attachment 34150 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34150&action=edit testcase Changing this->_M_impl._M_end_of_storage = __new_start + __len; to this->_M_impl._M_end_of_storage = __new_start + malloc_usable_size(__new_start) / sizeof(value_type); in vector.tcc makes the runtime of the attached program drop from 0.35 seconds to 0.24 seconds on my machine, a 31% reduction. This shows there is low hanging fruit for a very common operation (vector::push_back). A proper implementation would of course only do this for allocators that are known to be malloc frontends. :)