Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 jjrobert · Mar 21, 2012 at 10:17 PM · c#arraymemoryint

Best Way to Load 10^8 int Array in Unity/C#?

Hello,

I am building an AI to play Tetris and have compiled a large heuristic function in C#. Right now, the function is saved as a text file that I load into an array when I want to manipulate it. This 10^8 int array maps a state number to a heuristic value in this way:

array[state] = heuristic

I also have a Tetris platform built in C#/Unity. I would like to be able to access my heuristic information within this platform. However, Unity takes a very long time to read the file into memory.

I have looked into using a local database to read the information, but cannot find an easy one to set up with C# (most information I have found has to do with setting up DBs for MMO characters, which is a different problem).

I need a way to quickly load the entire heuristic into memory and perform lookups while the algorithm runs. Do you have any ideas or similar experience that could help me out?

Thanks!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DaveA · Mar 21, 2012 at 10:22 PM

I would pre-process that text file into a binary file with that data. 16 or 32bit ints? Either way, it's a big file. You could use the standard Stream-related API, but I'd put it in another thread for sure. And really I would look into making probably a separate (set of) file(s) which index into that large file, then only read the parts needed at any given time. I hope you don't want this on mobile like that. For mobile, I'd access it on a server via WWW and scripts on the server.

Comment
Add comment · Show 6 · 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
avatar image jjrobert · Mar 21, 2012 at 10:30 PM 0
Share

The text files I have now are right at 1GB!

I read the entire file into an array before my game begins execution. This works fine, it just takes a few $$anonymous$$utes to load before the game begins.

avatar image DaveA · Mar 21, 2012 at 10:41 PM 0
Share

It's going to. The best you can do if you want to parse that as text each time is put it in another thread or coroutine so it doesn't make you wait a few $$anonymous$$utes before you see anything.

avatar image jjrobert · Mar 21, 2012 at 11:38 PM 0
Share

Can you suggest another method for storing the data that will improve load time? $$anonymous$$y only thought is to store it in a local database, but I haven't been able to find an easy method for doing that in C# with Unity.

avatar image DaveA · Mar 22, 2012 at 12:10 AM 0
Share

As I said, store it as an array of ints (binary). Assu$$anonymous$$g 32-bit ints, that's 4 bytes per item, and you should be able to pretty much slam it into memory. Check http://www.dotnetperls.com/binaryreader and http://www.codeproject.com/Articles/10750/Fast-Binary-File-Reading-with-C

avatar image jjrobert · Mar 22, 2012 at 03:41 PM 0
Share

Thank you!

I converted my text file to binary and it loads a lot faster (~25 seconds as opposed to a few $$anonymous$$utes). This will really help with debugging my AI.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I want some ints stored in a new int right after eachother 1 Answer

Monodevelop is expecting int from my float array 3 Answers

bool[string] = true; array possible? 2 Answers

strange cloning array beviour 1 Answer

Array index help. 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