Byte problems

allencook200

Member
Joined
Apr 27, 2021
Messages
9
Programming Experience
1-3
So my server needs a way to send floats to the client. Doing this with binarywriter creates allocations when writing floats, but not integers.

So how I thought about solving this problem is just sending two integers. One for before the decimal, and one after, but then I have really no way of turning that back into a float without allocating memory again.

Any help is welcome.

Edit: It appears that this problem is related to unity only.
 
Last edited:
Okay so someone from unity helped me fix this general issue, but I still would like to know the proper low level way of getting the 4 bytes from a float.
 
A binary writer would use up memory regardless of sending an integer or a float. The data to hold those 4 bytes for either an integer or float had to be stored somewhere. I suspect that you are looking at the wrong measurement.

Anyway, if you are into unsafe code, C# let's you used pointers. Just point a byte pointer to the same location that an float is stored at.

If you are not until unsafe code, as I recall the framework has some memory or buffer related classes that let you get to the underlying bytes of a value type, or an array.
 
Back
Top Bottom