[swift-users] Help! Slicing an array is very expensive
Zhao Xin
owenzx at gmail.com
Mon May 8 21:55:30 CDT 2017
Have you try other approaches? Maybe just write your data to cache on disk
and read it back will be quicker?
Zhaoxin
On Tue, May 9, 2017 at 8:01 AM, Philippe Hausler via swift-users <
swift-users at swift.org> wrote:
> I wonder if Data might be a better tool for the job here since it is it’s
> own slice type and would avoid copying large amounts of data into temporary
> buffers.
>
> > On May 8, 2017, at 16:47, Rick Mann via swift-users <
> swift-users at swift.org> wrote:
> >
> > I have this C library that interacts with some hardware over the network
> that produces a ton of data. It tells me up front the maximum size the data
> might be so I can allocate a buffer for it, then does a bunch of network
> requests downloading that data into the buffer, then tells me when it's
> done and what the final, smaller size is.
> >
> > Thanks to previous discussions on the list, I settled on using a [UInt8]
> as the buffer, because it let me avoid various .withUnsafePointer{} calls
> (I need the unsafe buffer pointer to live outside the scope of the
> closures). Unfortunately, When I go to shrink the buffer to its final size
> with:
> >
> > self.dataBuffer = Array(self.dataBuffer![0 ..< finalBufferSize])
> >
> > This ends up taking over 2 minutes to complete (on an iPad Pro).
> finalBufferSize is very large, 240 MB, but I think it's doing a very naive
> copy.
> >
> > I've since worked around this problem, but is there any way to improve
> on this?
> >
> > Thanks,
> >
> > --
> > Rick Mann
> > rmann at latencyzero.com
> >
> >
> > _______________________________________________
> > swift-users mailing list
> > swift-users at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-users
>
> _______________________________________________
> 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/20170509/4612d9ce/attachment.html>
More information about the swift-users
mailing list