On Wednesday, 10 July 2013 at 18:22:24 UTC, Ali Çehreli wrote:
On 07/10/2013 11:10 AM, Sean Kelly wrote:
> On Jul 10, 2013, at 10:45 AM, Namespace
<rswhi...@googlemail.com> wrote:
>
>>> A string in D, and all arrays, is a struct looking like
this:
>>>
>>> struct Array (T)
>>> {
>>> T* ptr;
>>> size_t length;
>>> }
>>
>> I always thought it looks like this:
>>
>> struct Array(T) {
>> T* ptr;
>> size_t length, capacity;
>> }
>
> Sadly, no. The only way to determine the capacity of an
array is to query the GC.
>
And to be pedantic, length comes first:
struct Array (T)
{
size_t length;
T* ptr;
}
Which is actually property-like because assigning to length
does pretty complex stuff. So the member cannot be named as
'length':
struct Array (T)
{
size_t length_;
T* ptr;
}
Anyway... :)
Ali
Reminds me of how Delphi (aka Pascal) strings are work. Thanks
everyone this answers some of my questions. Now what about when
the return type of a function is a string? Is D returning the
pointer to the string structure or is it returning the structure?