orlandos-nl / BSON

Native Swift library for BSON (http://bsonspec.org)
https://orlandos.nl/docs/mongokitten/articles/bson
MIT License
109 stars 35 forks source link

Use native Data type for binary data #15

Closed a2 closed 7 years ago

a2 commented 8 years ago

Currently I need to convert from Foundation.Data to [UInt8] to insert some data into my BSON document. However, I need to allocate a ~300 kiB [UInt8] buffer to store the data, and my web app freezes. Therefore I'm wondering if maybe the native Data type should be used to avoid this transformation, which I already see here.

Obbut commented 8 years ago

We may improve support for Foundation.Data, but as BSON uses [UInt8] all over the place we won't be able to use this as the "native" data type without risking our performance. Also, [UInt8] has been the standard pretty much since the beginning of server side open source Swift.

However, I don't really see why allocating a buffer of that size would freeze your web app? How are you allocating this byte array?