Giter Club home page Giter Club logo

Comments (7)

httpdigest avatar httpdigest commented on August 24, 2024

Thanks for the improvement suggestions!

toString() is kinda an exception to this "no allocations" rule, which is also stated on the JOML readme above the paragraph that you quoted, for the following reasons:

  • toString() should only be used for debugging purposes (which is also the case why they use a formatter, in order to nicely align the columns when printing them on stdout/stderr)
  • a client should not rely on toString() in its "hot path"
  • by design, Object.toString() always allocates a String (and additionally an implicit StringBuffer in all but the most trivial cases)

Especially because of the last point we have lost anyway, because we cannot completely get rid of allocations in toString(), and because of the other points I saw no point in trying to make it allocate "the least amount" of memory.

But I went with another version of toString() taking a NumberFormat as parameter, which allows a client to externally specify how numbers should be formatted. Regarding String.format, we cannot currently use this unless we give up on being 1.4 compatible.
And if we take a look at String.format()'s source in a >= 1.5 JDK, we see that it also allocates a Formatter.

The vector and quaternion toString() methods make no use of formatting, because they need no number layouting.

from joml.

FortressBuilder avatar FortressBuilder commented on August 24, 2024

Regarding your last statement, I don't think vectors and quaternions "need no number layouting". It is currently a pain comparing them in the console (where I print one object every line), because the values don't align. I think it would not be much work but very useful especially for debugging to also have toString(NumberFormat) methods for these classes.

from joml.

httpdigest avatar httpdigest commented on August 24, 2024

Thanks for your comment!
Please make a GitHub fork of JOML. There you can add any methods needed by you to it and afterwards make a GitHub Pull Request to have them included in the upstream.
Thanks!

from joml.

httpdigest avatar httpdigest commented on August 24, 2024

I've changed the formatting of the matrix values to really always align perfectly.
See: a69ab48 and 24ab853

from joml.

FortressBuilder avatar FortressBuilder commented on August 24, 2024

Looks a lot nicer now. However, the quaternions and AngleAxis4f still have the commas. Is this intended?

from joml.

FortressBuilder avatar FortressBuilder commented on August 24, 2024

I removed the commas in this pull request: #11.

from joml.

httpdigest avatar httpdigest commented on August 24, 2024

Closing this now, since with the advent of toString(NumberFormat), the client is now able to specify the format which avoids that allocation.

from joml.

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.