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

[Feature Request] Apply more efficient allocate algorithm in `vector` #1

iosmanthus opened this issue Aug 4, 2019 · 0 comments


Copy link

commented Aug 4, 2019

Currently, our vector is too simple and have really bad performance in push/pop because we need to reallocate resource and execute memcpy when we add a new element to the end of the vector. Dynamic tables described in CLRS may be feasible in this situation.

template <typename T>
void Vec<T>::push(T data)
T* new_buf = new T[this->len + 1];
std::copy(this->buf, this->buf + this->len, new_buf);
new_buf[this->len] = data;
delete[] this->buf;
this->buf = new_buf;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.