Code Monkey home page Code Monkey logo

Comments (3)

madmann91 avatar madmann91 commented on May 24, 2024 1

See the documentation for std::make_unique.
Here's the relevant quote:
[std::make_unique] Constructs an array of the given dynamic size. The array elements are value-initialized. ...
As a reminder, value-initialization for int means zeroing.

from bvh.

Janos95 avatar Janos95 commented on May 24, 2024

Ah ok that makes sense, thanks. I was assuming (mistakenly) that you are using unique_ptr's to avoid value initializing the array. So the reason to use a unique_ptr instead of a std::vector is to communicate that the arrays dont change in length?

from bvh.

madmann91 avatar madmann91 commented on May 24, 2024

First of all, as you noticed, the arrays don't change in length, so there's no need to carry around a capacity field. Second, the size field of std::vector would also be redundant here: Those arrays have the same size as the number of nodes in the BVH.
To sum things up, this at the same time conveys the idea that the size does not change, and as an additional bonus makes the generated machine code a bit simpler and the class that contains those arrays thinner (not that this is a particular bottleneck, but still, it's a nice thing to have).

from bvh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.