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

Add a set of memory conversion methods to bevy_utils #5460

Closed
alice-i-cecile opened this issue Jul 26, 2022 · 7 comments
Closed

Add a set of memory conversion methods to bevy_utils #5460

alice-i-cecile opened this issue Jul 26, 2022 · 7 comments
Labels
A-Utils Utility functions and types C-Feature A new feature, making something new possible

Comments

@alice-i-cecile
Copy link
Member

I would actually prefer to have a function on bevy_utils that formats a memory measurement to KiB, MiB, GiB, ... depending on the value. Memory measurements will be quite common in game engines.

Originally posted by @Nilirad in #5454 (comment)

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy A-Utils Utility functions and types labels Jul 26, 2022
@mockersf
Copy link
Member

mockersf commented Jul 26, 2022

I disagree, this doesn't need to be part of Bevy.

@alice-i-cecile alice-i-cecile removed the D-Trivial Nice and easy! A great choice to get started with Bevy label Jul 26, 2022
@alice-i-cecile
Copy link
Member Author

Closing until we can find a clear motivation. This may fit well as a truly external crate that we import for the editor.

@mockersf
Copy link
Member

mockersf commented Jul 26, 2022

quick search found https://crates.io/crates/unit-conversions

@IceSentry
Copy link
Contributor

For the record, I didn't use it in my PR because I didn't want to add a crate for what was essentially just a multiplication in my case.

Once we start needing to show this in a more friendly manner in the future editor that crate would be a good starting point, but it doesn't have a distinction between GiB and GB which is not ideal in my opinion. It's a bit weird considering they do have KiB vs KB.

@Nilirad
Copy link
Contributor

Nilirad commented Jul 26, 2022

Also that crate doesn't help to automatically display the more convenient unit based on the value.

@alice-i-cecile
Copy link
Member Author

We should see about PRs to fix those limitations upstream (and existing alternatives) before trying to fork IMO.

@Nilirad
Copy link
Contributor

Nilirad commented Jul 26, 2022

Actually, I was not thinking to do unit conversion (as returned value), but just formatting a value.

We can easily achieve it by creating a newtype on a numeric value (e.g. i64) and implement the Display trait for it that will use the most convenient binary unit (what is most convenient has to be defined). Additionally, it may also have methods such as bytes_to_string, kibibytes_to_string, as kilobytes_to_string and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Utils Utility functions and types C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

4 participants