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.