简体   繁体   English

数组结构需要建议

[英]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? 还是我应该只使用其他东西,例如arraylist或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 阅读有关锯齿阵列的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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