简体   繁体   中英

arrays of structs need advice

I made an array of structs to represent map data that gets drawn; however I didn't double check it till it was too late: when I load in a new map I get either an "out of memory exception" (if i try to make a new array struct first) or I get a screwed up map that would require a lot of recodeing to get it to work right (if i just initialize a big map first)... maybe too much.

So now I'm wondering if there's a safe way to reallocate the array of structs since the data when I do it is thrown away anyway (ie I dont need to copy the data, just resize the array and reset new data from the file).

Is this possible safely? Or should I just look to use something else, like an arraylist or list? What I need here is basically indexing speed and reading speed more then anything.

A large and contiguous block of memory is sometimes difficult to allocate. Consider allocating more jagged data. Access time will be slightly degraded, but you will be able to allocate more memory.

Read more about jagged arrays

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM