Re: [Vala] User managed memory?



Hello,

there is already a delete keyword defined for pointers, and I think it
is the only
way to free pointers, if you don't use the delete statement you are
leaking the allocated memory,
here is an example:

== example.vala
using GLib;

public struct Example {
  public int first;
  public int second;
}

public static void main (string[] args) {
  Example* example = new Example[1];
  message ("Example created");
  delete example;
  message ("Example deleted");
}
==

and this will be translated to this:
== example.c
...
Example* example;
example = g_new0 (Example, 1);
g_message ("example.vala:10: Example created");
g_free (example);
g_message ("example.vala:12: Example deleted");
...
==

Gr,
Thijs

2008/11/14 Kaan Yamanyar <kaan yamanyar com>:
Hi,

I appreciate wonderful work you are dealing with. I was looking for similar
idea for Java then I suddenly came face-to-face with this project.

I hope to see a better eclipse plug-in which integrates easily with full
support such syntax highlighting, building, debugging and it is for windows.

Also, I wonder: If you define (if you had not defined already) a keyword
like "delete" for memory management (so the developer is fully responsible
for memory management), would performance be better? (Please see added line
21 to your List Example below:)

KR,
Kaan Yamanyar

01 using GLib;
02
03 public static int main (string[] args) {
04    List<string> list = new List<string> ();
05    list.append ("one");
06    list.append ("two");
07    list.append ("three");
08
09    stdout.printf ("list.length () = %u\n", list.length ());
10
11    // Traditional iteration
12    for (int i = 0; i < list.length (); i++) {
13        stdout.printf ("%s\n", list.nth_data (i));
14    }
15
16    // Comfortable iteration
17    foreach (string element in list) {
18        stdout.printf ("%s\n", element);
19    }
20
21    delete list; //USER MANAGED MEMORY ??
22    return 0;
23 }



_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list





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