简体   繁体   English

NSData dataWithContentsOfFile与NSInputStream

[英]NSData dataWithContentsOfFile vs NSInputStream

I have to process XML, now using NSInputStream breaks my code as I have to rewrite lots of things. 我必须处理XML,现在使用NSInputStream会破坏我的代码,因为我必须重写很多东西。

Will dataWithContentsOfFile entire file into memory, or only read contents requested for getBytes method? dataWithContentsOfFile会将整个文件放入内存,还是仅读取getBytes方法请求的内容?

I am using NSData as input parameter to NSXMLParser, I wonder is there any documentation regarding this? 我正在使用NSData作为NSXMLParser的输入参数,我想知道是否有与此相关的文档?

There is no documentation on apple's doc regarding internals of NSData's dataWithContentsOfFile or its implementation. 苹果的文档上没有关于NSData的dataWithContentsOfFile内部或其实现的文档。

When you allocating NSData for NSXMALParser ,it means creating data buffer for that object and every object occupy memory (RAM) ,because iPhone IOS know very well how to use virtual memory. 当为NSXMALParser分配NSData时,这意味着为该对象创建数据缓冲区,并且每个对象都占用内存(RAM),因为iPhone IOS非常了解如何使用虚拟内存。 When you reading entire data from the file, it occupying object data and if the data size is more than a few(depended upon OS algo) memory pages, the object uses virtual memory management. 当您从文件中读取整个数据时,它会占用对象数据,并且如果数据大小超过几个(取决于OS算法)内存页,则该对象将使用虚拟内存管理。 A data object can also wrap preexisting data, regardless of how the data was allocated. 数据对象还可以包装预先存在的数据,而不管数据是如何分配的。 The object contains no information about the data itself (such as its type); 该对象不包含有关数据本身的信息(例如其类型)。 the responsibility for deciding how to use the data lies with the client. 决定如何使用数据的责任在于客户。 In particular, it will not handle byte-order swapping when distributed between big-endian and little-endian machines. 特别是,当在大端和小端机器之间分配时,它将不处理字节顺序交换。
I recommend you to read again this link https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/BinaryData/BinaryData.html#//apple_ref/doc/uid/10000037i its related to iOS. 我建议您再次阅读此链接https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/BinaryData/BinaryData.html#//apple_ref/doc/uid/10000037i与iOS相关。 But yes one thing concern with you ….in IOS there is type of owner of object. 但是,是的,与您有关的一件事情……在IOS中,存在对象所有者的类型。 One is user and another one is IOS object. 一个是用户,另一个是IOS对象。 if you creating NSData that means you allocating memory buffer and assigning data pointer to this veriable, but at that moment entire data is resides inside memory. 如果创建NSData,则意味着您分配了内存缓冲区并为该Veriable分配了数据指针,但此时所有数据都位于内存中。 Its our assumption, but during this period IOS know how to handle this scenario. 这是我们的假设,但是在此期间IOS知道如何处理这种情况。 IOS uses vertual memory technique to handle data pages. IOS使用垂直存储技术来处理数据页。

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

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