On 11/08/2013 05:47 PM, Igor Bukanov wrote:
  C++'s `string` and `vector<T>` are objects containing two or three pointers.

For that one pays performance penalty in C++ as string and vector
instances are passed by references resulting in double indirection
when accessing the elements. I suppose it could help to think about
strings in Rust similar to variable-sized structs in C like:

struct MyString {
     unsigned int bytelength;
     unsigned int data[];
};

As in Rust such struct cannot be instantiated and one typically uses
malloc/alloca to allocate instances and then just pass around the
resulting pointers.

I like this version precisely for the reason it avoids double indirection. I use it whenever I need "weighted strings" in C (strings that know their weight, Pascal strings in fact) [1]. It works fine, is easy on the implementation side, just terribly annoying w/o syntactic support. Same for arrays, both fixed (but variable, in the sense of not predefined) and dynamic size. It's all fine in my view for a language like Rust, provided it remains an implementation choice. Meaning, whether the representation of say a static array is a {p, n} struct or such a variable-sized structs is transparent on the language side.

What are the present implementations of strings and arrays in Rust? And what about fixed size (esp for strings)?

Denis

[1] Actually, I rather just use a pointer, with the size written before the first string byte or array item, like true Pascal strings, but the result is the same.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to