简体   繁体   English

NSMutableData错误(iPhone)

[英]NSMutableData bugs (iPhone)

I use NSMutableData objects to store lists of 32 byte structs that represent series data. 我使用NSMutableData对象存储代表系列数据的32字节结构的列表。 These series are potentially extended, added, aligned, etc. To save allocation of unnecessary objects I try to extend and append bytes to existing objects rather than allocate new ones. 这些系列可能会进行扩展,添加,对齐等操作。为了节省不必要对象的分配,我尝试将字节扩展并追加到现有对象上,而不是分配新对象。

I noticed some strange behavior in the simulator today: 1) using setLength and increaseByLength didn't always zero all new bytes and 2) use of these objects after modification resulted in crashes. 我今天在模拟器中注意到了一些奇怪的行为:1)使用setLength和gainByLength并不总是将所有新字节清零,以及2)修改后使用这些对象导致崩溃。 The crashes were all in very different areas but always EXC_BAD_ACCESS. 崩溃全都在非常不同的区域,但总是EXC_BAD_ACCESS。 After quite a bit of debugging I ended up allocating new objects for working with via mutableCopy and assigning them to my object attributes when done. 经过大量的调试后,我最终通过mutableCopy分配了新对象以供使用,完成后将它们分配给我的对象属性。 That solved all of the issues I was having. 那解决了我遇到的所有问题。

* I am working with these objects in background threads but have wrapped all operations in a synchronized block and have not been able to observe any race conditions on the objects in question. *我正在后台线程中处理这些对象,但是将所有操作包装在一个同步块中,并且无法观察到有关对象的任何竞争情况。

Has anyone noticed similar oddities? 有没有人注意到类似的怪胎?

Thanks. 谢谢。

I haven't received an answer for this so I thought I'd follow up with my solution. 我还没有得到答案,所以我想我会继续解决我的问题。 I ended up reallocating new NSData / NSMutableData objects as I need them and working with the memory directly before wrapping it in NSData objects. 我最终根据需要重新分配了新的NSData / NSMutableData对象,并在将其包装到NSData对象之前直接使用了内存。

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

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