[Vala] Pointers and Memory Management
- From: Jürg Billeter <j bitron ch>
- To: vala-list gnome org
- Subject: [Vala] Pointers and Memory Management
- Date: Sat, 15 Dec 2007 13:51:08 +0100
I've just committed initial support for pointers to class instances. The
main differences between references and pointers are the following:
* Vala manages the memory when using references (usually with
reference counting) but Vala doesn't manage the memory when
using pointers, i.e. if you use pointers, you have to ensure
that there are no memory leaks and that you never access invalid
objects, just like in C.
* Pointers will support pointer arithmetic and element access in
the future.
It's recommended to use references whenever possible to benefit from
automatic memory management. The reason why I'm adding full support for
pointers to Vala is to make it easier to use C libraries not supporting
reference counting, as for example libxml2.
Syntax is similar to C/C# pointers, e.g.
Node* node = new Node ();
Note that the * is a normal part of the type and not part of the
declarator, i.e. you declare multiple pointers as follows:
Node* node1, node2;
Pointer support is by far not complete yet, so tell me when you need a
specific feature in your application and I'll try to add it as soon as
possible.
I've also removed the --disable-memory-management option from valac, as
you will be able to do manual memory management with pointers and I want
to avoid redundant language variants.
Jürg
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]