Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PhobicGunner · Apr 22, 2016 at 08:16 PM · networkingil2cppgarbage-collection

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JoshPeterson · Apr 25, 2016 at 11:56 AM 0
Share

This certainly should not be the case. I'm not specifically familiar with the UNET code you are referring to though. Can you provide more details about which code this is? Or is this something that can be caused without UNET? If you can provide a standalone test case to reproduce this, that would really help us. Thanks!

avatar image PhobicGunner JoshPeterson · Apr 25, 2016 at 05:50 PM 0
Share

It's in NetworkWriter.cs, starting on line 261 (looking at the source in BitBucket). It appears that it uses a union struct normally, but that part is completely compiled out if INCLUDE_IL2CPP is defined, in favor of BitConverter.ToUInt32(BitConverter.GetBytes(value), 0), which as far as I can tell would allocate a byte array because of the call to GetBytes.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PrimalCoder · Oct 29, 2017 at 01:24 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

59 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Mirror Networking - can't create a server on a build game, IL2CPP Mistake 0 Answers

Asynchronous Sockets still have problem in 4.6.3f1 with IL2CPP 3 Answers

.net socket disconnection exception 0 Answers

A sample project with a networkView componet on the camera project compile successfully but not run in ios device 1 Answer

PUN Socket error 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges