ByteSize icon indicating copy to clipboard operation
ByteSize copied to clipboard

Partial bytes do not exist

Open Rainmaker52 opened this issue 3 years ago • 3 comments

I'm trying to use this library to keep my code a bit more readable.

If I do this:

var memoryBuffer = MemoryPool<byte>.Shared.Rent((int) ByteSize.FromKibiBytes(128).Bytes);

I have to cast .Bytes to an integer, because the Bytes property is a double. I can understand returning a double for almost anything. But seeing as "Bytes" in particular, is really the lowest addressable data type, there is no way to have "partial bytes". You would never be addressing "1.2 bytes".

I would therefore suggest changing the "Bytes" type to an uint or ulong (I really don't see negative bytes as a thing either, but I could be wrong there).

Rainmaker52 avatar Feb 01 '22 14:02 Rainmaker52

The library supports bits which don't have to be a multiple of 8 (and thus giving you a fractional bytes count). I don't really see the purpose of that though if I'm being honest and would agree that having the bytes be an integer would make more sense.

RayCarrot avatar Oct 11 '22 11:10 RayCarrot

(int) ByteSize.FromKibiBytes(128).Bytes

Int32 goes up to 2147483647. That's 2 GiB. That would not be a good candidate to represent file sizes.

You should not use the int type to represent file size.

sandrock avatar Oct 11 '22 11:10 sandrock

(int) ByteSize.FromKibiBytes(128).Bytes

Int32 goes up to 2147483647. That's 2 GiB. That would not be a good candidate to represent file sizes.

You should not use the int type to represent file size.

Yes. As I mentioned, I suggest unit or ulong

The cast, in this case, was necessary because of the function signature requiring a signed int. Which is stupid, but not under my control.

Rainmaker52 avatar Nov 05 '22 12:11 Rainmaker52