Any way to set len and ptr in dyn arrays?

nobody nobody at mailinator.com
Tue Aug 8 05:32:54 PDT 2006


Frank Benoit wrote:
> nobody schrieb:
>> Tom S wrote:
>>> nobody wrote:
>>>>   theArray.myArrayInternals.len = buf[0] * buf[1];
>>>>   theArray.myArrayInternals.ptr = &buf[2];
>>> erm ...
>>>
>>> foo = (&buf[2])[0 .. buf[0] * buf[1]];
>> Thanks for your answer. I understand that would ultimately have the same
>> result. My question is about whether that directly sets the len and ptr
>> fields or are does more stuff happen. If so what is it? If not then why
>> is there no direct access to the ptr and len fields?
>>
> 
> This builds a slice, which is like setting ptr/length of an array. This
> is called slicing. Instead of Toms example, I think you can also write this:
> foo = buf[ 2 .. buf[0] * buf[1] + 2 ];
> 

Thanks to you also for your response. I was trying to suggest 
before that I understand how slicing ends up -- ie with ptr and 
len as I desired. I am worried about what happens while the 
slicing happens. I am worried about any gotchas.



More information about the Digitalmars-d-learn mailing list