Basic
Last updated
Last updated
All examples except gpseq are run and compiled with the vala filename command.vala
Std means GLib
Get Twitter Status
Async Server Example
Connect to localhost via netcat or telnet on port 3333 and issue a command ending with a newline. echo "blub" | nc localhost 3333
Классы выделяются на куче. Memory for classes is allocated on the Heap.
Things u can do with classes:
owned get means that the object will own the link after the transfer, that is, it is like move semantics in C++
In Vala, as in Go, there is no function overload, but you can use named constructors and default arguments
В Vala как и в Go нету перегрузки функций, но можно использовать именованные конструкторы и аргументы по умолчанию
On the 11th line, you can see the creation of a class with some arguments specified without a constructor. This is similar to named function arguments.
На 11той строке вы можете увидеть создание класса с заданием некоторых аргументов без конструктора. Это похоже на именованные аргументы функций.
Структуры выделяются на стеке Memory for structs is allocated on the Stack.
Sum using divide and conquer:
If you comment out the blocking
block and put only Thread.usleep
then the program will run for a time equal to the number of running threads divided by the number of threads of your processor.
With blocking
, it is equal to the execution time of a single thread, that is, one second. This is called work stealing
. When a thread starts waiting for something, such as a packet from the network, another thread steals its CPU time and starts working until the first thread waits for the event it needs.
Если вы закомментируете blocking
блок и оставив только Thread.usleep
, то программа будет работать в течение времени, равного числу запущенных потоков, деленному на число потоков вашего процессора.
C blocking
оно равно времени выполнения одного потока, то есть одной секунде. Это называется work stealing
. Когда поток начинает чего то ожидать, например пакета из сети, другой поток ворует у него процессорное время и начинает работать, пока первый не дождется нужного ему события.
Vala supports three different types of class:
GObject subclasses are any classes derived directly or indirectly from GLib.Object. This is the most powerful type of class, supporting all features described in this page. This means signals, managed properties, interfaces and complex construction methods, plus all features of the simpler class types.
Fundamental GType classes are those either without any superclass or that don't inherit at any level from GLib.Object. These classes support inheritence, interfaces, virtual methods, reference counting, unmanaged properties, and private fields. They are instantiated faster than GObject subclasses but are less powerful - it isn't recommended in general to use this form of class unless there is a specific reason to.
Compact classes, so called because they use less memory per instance, are the least featured of all class types. They are not registered with the GType system and do not support reference counting, virtual methods, or private fields. They do support unmanaged properties. Such classes are very fast to instantiate but not massively useful except when dealing with existing libraries. They are declared using the Compact attribute on the class, See
- Functional templating for Vala.
Memory for Compact classes is allocated by monster.