[Vala] Fwd: What is the right syntax for defining pointers or references or "aliases" in Vala ?



---------- Forwarded message ----------
From: Serge Hulne <serge hulne gmail com>
Date: Mon, Jun 20, 2011 at 10:02 PM
Subject: Re: [Vala] What is the right syntax for defining pointers or
references or "aliases" in Vala ?
To: tecywiz121 <tecywiz121 hotmail com>


I am not sure. The following:

///
using Posix;

void main (string[] argv) {

   string a = "hello";
   string b = a;

   Posix.stdout.printf("a = %p\n", &a);
   Posix.stdout.printf("b = %p\n", &b);
}
///

yields :

a = 0x7fff5fbff890
b = 0x7fff5fbff880

Serge.


On Mon, Jun 20, 2011 at 9:55 PM, tecywiz121 <tecywiz121 hotmail com> wrote:
On Mon, 2011-06-20 at 21:39 +0200, Serge Hulne wrote:
What is the Vala syntax to express that :

b is a alias of a (or b points to the same address that a or b is a
reference to a).

Is there a way to express this in vala or does *assignment always mean
memory allocation* in Vala.

I'm not an expert, but I'm pretty sure that with classes, assignment
means setting the variable to point to the object, and increasing the
object's reference count.

I'm not entirely sure what happens with structures though.

In other terms : How do you store references to variables (or pointers
to variables) in, say, a container (a libgee data structure) while
avoiding duplication of said data.

Use the variables directly.

In C or C++ this would be done with pointers (or references).

Most variables in vala are pointers to objects.


Sam




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