Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

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

Open
iosmanthus opened this issue Aug 4, 2019 · 0 comments
Open
Labels
collections Collections type easy issue that easy to solve enhancement New feature or request

Comments

@iosmanthus
Copy link
Contributor

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;
this->len++;
}

@iosmanthus iosmanthus added easy issue that easy to solve collections Collections type labels Aug 4, 2019
@iosmanthus iosmanthus added the enhancement New feature or request label Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
collections Collections type easy issue that easy to solve enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant