[swift-users] When does `Data.init?(capacity:)` fail?

Karl razielim at gmail.com
Sun Jun 19 11:59:58 CDT 2016


As I understand it, that’s not an error in the ‘try’ sense of the word. If that failure happens, it’s a catastrophic issue which should bring down the application.

So the initialiser shouldn’t be failable; you’re right. File a bug at bugs.swift.org.

Karl

> On 18 Jun 2016, at 06:06, Saagar Jha via swift-users <swift-users at swift.org> wrote:
> 
> This <http://article.gmane.org/gmane.comp.lang.swift.user/1702> might be relavant. Basically, Data’s init will fail if memory can’t be allocated for it.
> 
> 
> 
> On Fri, Jun 17, 2016 at 11:38 AM Adrian Zubarev via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> Hello there, I’m trying to optimize my code and reduce copying from different buffers into a new one.
> 
> I thought I just create a Data value with enough capacity and write directly into it. My problem is that Data.init?(capacity:) can fail, but why and when?
> 
> Can someone explain this behavior to me?
> 
> I’m sending data via TCP sockets and when recn function write directly into a Data struct.
> 
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
> -- 
> -Saagar Jha
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160619/8f260b05/attachment.html>


More information about the swift-users mailing list