UNET & IL2CPP memory allocation?

So, after taking a peek in the internal code for UNET it seems that normally, for serializing some simple numeric types, UNET uses a union struct so that it can for example it can take a float, get the uint formed by the raw bytes of that float, and then serialize that, without generating memory. But, apparently, in the case of IL2CPP, it doesn’t do that. Instead, it uses BitConverter.GetBytes to get a byte array of the float or double and serializes the byte array.

The problem is, as far as I can tell this means a four-byte array is allocated for every single float which is serialized to a stream when compiling for IL2CPP.

Am I missing something, or does serializing floats really allocate that memory? It seems like IL2CPP should be able to handle unions, given that C++ definitely supports this sort of logic.

I have not looked in the latest versions to see if it’s still true, but at the time you asked the question it really was true that serializing floats allocated memory as you described.

Our solution was to convert the floats to ints before serialization using a utility class like this one FloatConversion.cs