byte* and int length -> byte[]

Jimmy Cao jcao219 at gmail.com
Mon Aug 15 10:21:11 PDT 2011


On Mon, Aug 15, 2011 at 12:16 PM, mimocrocodil <4denizzz at gmail.com> wrote:

> I obtain immutable(byte)* and int where contained length of bytes block
> from C library.
>
> Can I convert this into byte[] without explict copying etc.
>
> Something like:
>
> byte* p; // bytes
> int size; // size of bytes block
>
> byte[] b;
> b.length = size;
> b.ptr = p;
>
> // now b contains bytes from library
>


Yes:

byte[] b = p[0 .. size];
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110815/e0c8deaa/attachment.html>


More information about the Digitalmars-d-learn mailing list