September 12, 2002 Re: Some more ideas | ||||
---|---|---|---|---|
| ||||
Posted in reply to chris jones | "chris jones" <flak@clara.co.uk> wrote in message news:alo02r$njr$2@digitaldaemon.com... > Thats how Delphi does it, a dynamic array is a pointer, the first 2 words of > the memory block are the ref count and the number of elements . The pointer > points to the first element of the array so the ref cound is at -8 and lenght is at -4. That will work, but it's slower than D's implementation. It also makes slices not possible without copying. > Also in delhpi strings are arrays with copy on write but the neat thing Delphi does is that it automaticly maintans a trailing null char at the end. > So to cast a delphi string to a C string you just point at the first char, zero overhead. And because the lenght is stored you dont have to scan the string to determine its length. D in general tries to put 0 bytes at the ends of character strings for the same reason, but it is not possible for slices. |
Copyright © 1999-2021 by the D Language Foundation