Skip to content

Replace some uses of malloc/free with std::unique_ptr #1069

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

Merged
merged 3 commits into from
Feb 7, 2020

Conversation

HackerFoo
Copy link
Contributor

Description

malloc() and free() can be error-prone, so I'm working on replacing them with safer alternatives, but without adding overhead.

Related Issue

#506

Motivation and Context

See issue above.

How Has This Been Tested?

I've run vtr_reg_strong tests.

Types of changes

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

@probot-autolabeler probot-autolabeler bot added lang-cpp C/C++ code VPR VPR FPGA Placement & Routing Tool labels Dec 20, 2019
@HackerFoo
Copy link
Contributor Author

Maybe std::vector can be used if the overhead of the bounds checks are acceptable.

Signed-off-by: Dustin DeWeese <[email protected]>
@mithro
Copy link
Contributor

mithro commented Jan 24, 2020

Looks like this is failing on valgrind test?

Signed-off-by: Dustin DeWeese <[email protected]>
@HackerFoo
Copy link
Contributor Author

I couldn't convert the heap to use new[]/delete[] without larger changes:

// Note: malloc()/free() must be used for the heap,
// or realloc() must be eliminated from add_to_heap()
// because there is no C++ equivalent.

The right thing to do is probably to use a std::vector.

@HackerFoo HackerFoo requested review from kmurray and acomodi January 29, 2020 00:44
@HackerFoo HackerFoo changed the title replace some uses of malloc/free with std::unique_ptr Replace some uses of malloc/free with std::unique_ptr Jan 29, 2020
@kmurray
Copy link
Contributor

kmurray commented Jan 31, 2020

Maybe std::vector can be used if the overhead of the bounds checks are acceptable.

I agree, unless we have a particular reason otherwise using a std::vector makes sense. There should not be any overhead with the regular operator[] on a vector, as it doesn't do bounds checking (only at() does).

@HackerFoo
Copy link
Contributor Author

I'll try replacing the malloc'ed heap with a std::vector, but I'd like to do that in another PR.

@kmurray
Copy link
Contributor

kmurray commented Feb 6, 2020

I'll try replacing the malloc'ed heap with a std::vector, but I'd like to do that in another PR.

As in, merge this PR and do the vector conversion in a follow up PR? Or just a new PR? Either way seems reasonable to me.

@HackerFoo
Copy link
Contributor Author

HackerFoo commented Feb 7, 2020 via email

@kmurray kmurray merged commit f7cc950 into verilog-to-routing:master Feb 7, 2020
@kmurray
Copy link
Contributor

kmurray commented Feb 7, 2020

Sounds good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-cpp C/C++ code VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants