Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
July 25, 2008 What does it mean: buffer[0 .. kSize] = input[index .. (index + Size)]; | ||||
---|---|---|---|---|
| ||||
Hello, I found some code in D and I am wondering what does it mean: buffer[0 .. Size] = input[index .. (index + Size)]; I understand it can be written like this: for (i=0; i<Size; i++) buffer[i]=input[i+index]; But... 1) does it allocate space for buffer? 2) if buffer has already some data- will be zeroed? 3) if there is no enough date (less then Size) in input will there be an exception or will be copied what already is in the array? Regards, t0mek |
July 25, 2008 Re: What does it mean: buffer[0 .. kSize] = input[index .. (index + Size)]; | ||||
---|---|---|---|---|
| ||||
Posted in reply to t0mek | On Fri, 25 Jul 2008 12:50:36 +0400, t0mek <t0mek@com.com.com.com.com> wrote:
> Hello,
> I found some code in D and I am wondering what does it mean:
> buffer[0 .. Size] = input[index .. (index + Size)];
>
> I understand it can be written like this:
> for (i=0; i<Size; i++) buffer[i]=input[i+index];
> But...
> 1) does it allocate space for buffer?
> 2) if buffer has already some data- will be zeroed?
> 3) if there is no enough date (less then Size) in input will there be an exception or will be copied what already is in the array?
>
> Regards,
> t0mek
It is *exactly* the same (however, a memcpy could be used under the hood), i.e.
- there is no allocation
- data will be overwritten
- an OutOfBounds exception will be thrown if array is not large enough
|
July 25, 2008 Re: What does it mean: buffer[0 .. kSize] = input[index .. (index + Size)]; | ||||
---|---|---|---|---|
| ||||
Posted in reply to Koroskin Denis | > It is *exactly* the same (however, a memcpy could be used under the hood), i.e.
> - there is no allocation
> - data will be overwritten
> - an OutOfBounds exception will be thrown if array is not large enough
Thanks!
Regards,
t0mek
|
July 25, 2008 Re: What does it mean: buffer[0 .. kSize] = input[index .. (index + | ||||
---|---|---|---|---|
| ||||
Posted in reply to Koroskin Denis | Koroskin Denis:
> - an OutOfBounds exception will be thrown if array is not large enough
If compiled in -release mode no exception is thrown, I think.
Bye,
bearophile
|
July 25, 2008 Re: What does it mean: buffer[0 .. kSize] = input[index .. (index +Size)]; | ||||
---|---|---|---|---|
| ||||
Posted in reply to Koroskin Denis | Reply to Koroskin, > On Fri, 25 Jul 2008 12:50:36 +0400, t0mek <t0mek@com.com.com.com.com> > wrote: > >> Hello, >> I found some code in D and I am wondering what does it mean: >> buffer[0 .. Size] = input[index .. (index + Size)]; >> I understand it can be written like this: >> for (i=0; i<Size; i++) buffer[i]=input[i+index]; >> But... >> 1) does it allocate space for buffer? >> 2) if buffer has already some data- will be zeroed? >> 3) if there is no enough date (less then Size) in input will there be >> an >> exception or will be copied what already is in the array? >> Regards, >> t0mek > It is *exactly* the same (however, a memcpy could be used under the > hood), Not /exaltly/ the same, because IIRC the exception will be thrown before any copy takes place and the for loop will copy to the end of one of the buffers and then throw. Most of the time the difference isn't important, but... > i.e. > - there is no allocation > - data will be overwritten > - an OutOfBounds exception will be thrown if array is not large enough |
Copyright © 1999-2021 by the D Language Foundation