[Vala] Vala : Suggestion for improvement : String Class wrapper for strings in Vala



Suggestion:
=========
A class wrapper for the string type in Vala, in order to avoid
duplication of data in assignments (which would yield an unnecessarily
huge memory usage when processing a large amount of text with a lot of
assignments).

if you compare the C code generated by Vala for:

1)

///
class String {
    public string s;
}

void main (string[] argv) {
    String a = new String();
    a.s = "hello";
    String b = a;
    stdout.printf("a.s = %s\n", a.s);
    stdout.printf("b.s = %s\n", b.s);
}
///


To :

2) the C code generated by Vala for:

///
void main (string[] argv) {
    string a = "hello";
    string b = a;
    stdout.printf("a = %p\n", &a);
    stdout.printf("b = %p\n", &b);
}
///

You will notice that in the second case (the naive straightforward
formulation) the data is duplicated (passed by value in the
assignment) whereas in the first case (which uses a class wrapper) the
object a is assigned to b by reference (not by value, i.e. the data is
not duplicated)


Serge.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]