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

Support reserve like std::vector<T>::reserve in C++ #2232

Closed
czgdp1807 opened this issue Jul 30, 2023 · 2 comments · Fixed by #2238
Closed

Support reserve like std::vector<T>::reserve in C++ #2232

czgdp1807 opened this issue Jul 30, 2023 · 2 comments · Fixed by #2238
Assignees

Comments

@czgdp1807
Copy link
Collaborator

czgdp1807 commented Jul 30, 2023

It looks like reserve makes a big difference here, so we should support it in LPython as well. For example by from lpython import reserve and just call this function. The CPython implementation will not do anything.

Here is how to use it:

from lpython import reserve
def dijkstra_shortest_path(n: i32, source: i32) -> i32:
    i: i32; j: i32; v: i32; u: i32; mindist: i32; alt: i32; dummy: i32; uidx: i32
    dist_sum: i32;
    graph: list[i32] = []
    dist: list[i32] = []
    reserve(graph, n*n)

In CPython emulation this will be an empty function (no-op), in LPython we reserve the memory for this list, similar to reserve in C++, for performance.

Originally posted by @certik in #2231 (comment)

@czgdp1807
Copy link
Collaborator Author

@kabra1110 Please keep it a high priority so that we can benchmark it against equivalent C++ code in #2231.

@certik
Copy link
Contributor

certik commented Jul 30, 2023

Duplicate of #2233.

@czgdp1807 czgdp1807 changed the title Support list_reserve like std::vector<T>::reserve in C++ Support reserve like std::vector<T>::reserve in C++ Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants