Change autovector to have a reserved size in LITE mode (#6868)
Summary: Previously in LITE mode, an autovector did not have a reserved size. When elements were added to the vector, the underlying array could be reallocated. There was a set of code that never expands the autovector and was doing &autovector::back(). When the vector is resized, the old addresses may become invalid, causing a later exception to be thrown. By reserving space in the autovector up front, this problem is eliminated for those uses where the vector will never exceed the initial size. the resize happens, these pointers become invalid, leading to SEGV or other exceptions. This change allows the autovector to be fully populated before we take the address of any of its elements, thereby elminating the potential for a resize. There is comparable code to this change in Version::MultiGet for dealing with the context objects. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6868 Reviewed By: ajkr Differential Revision: D21693505 Pulled By: cheng-chang fbshipit-source-id: e71d516b15e08f202593cb80f2a42f048fc95768
This commit is contained in:
parent
292bcf6227
commit
826295a5e9
@ -19,6 +19,12 @@ namespace ROCKSDB_NAMESPACE {
|
||||
template <class T, size_t kSize = 8>
|
||||
class autovector : public std::vector<T> {
|
||||
using std::vector<T>::vector;
|
||||
|
||||
public:
|
||||
autovector() {
|
||||
// Make sure the initial vector has space for kSize elements
|
||||
std::vector<T>::reserve(kSize);
|
||||
}
|
||||
};
|
||||
#else
|
||||
// A vector that leverages pre-allocated stack-based array to achieve better
|
||||
|
Loading…
Reference in New Issue
Block a user