GithubHelp home page GithubHelp logo

Comments (3)

Cazadorro avatar Cazadorro commented on August 17, 2024

I'm unsure of the exact reasoning, but I can tell you for me, std::pair is kind of annoying to deal with, .first and .second don't really specify what the members mean, plus AttributePair is self documenting in a way.

&std::get<0>(attrs.front()) is way less readable than &attrs.front().mAttribute in my opinion. I don't really have an easy place to figure out what conceptual member I'm std::geting. mAttribute makes this easy, I'm getting a reference to the attribute part of the attribute pair array. It also has the added bonus of auto-completing in the IDE so I technically have less to type (not that this is a reason to change it).

This is a common pattern outside of this repo as well, and even in other languages.

from alure.

kcat avatar kcat commented on August 17, 2024

The AttributePair struct, besides giving more descriptive names to the members, helps guarantee the attribute and value are stored in a trivially copyable type, essentially meaning the raw data can be accessed (std::pair is rather complicated when it comes to being trivial). The reason for this is the same reason the attributes need null termination, because it's passed directly to OpenAL without further interpretation. OpenAL itself requires either a null attribute list, or a contiguous sequence of integers representing a series of {attribute, value} pairs that ends with a 0 attribute. If the array given to Alure doesn't have the null termination, it needs to be copied to ensure there is one.

The reason std::unordered_map can't be used is because of that contiguous layout requirement. Also, despite its name, an unordered_map does have ordering, just that the app can't rely on any particular order (it uses hashed keys, where the hashing algorithm is implementation-defined).

from alure.

McSinyx avatar McSinyx commented on August 17, 2024

Thank you both for the prompt explanation! My mind now settled so I can continue on wrapping this in Cython. I guess I can close the issue at this moment.

from alure.

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.