[Vala] Help needed with unowned objects
- From: Tambet <qtvali gmail com>
- To: vala-list gnome org
- Subject: [Vala] Help needed with unowned objects
- Date: Thu, 30 Jun 2011 19:14:41 +0300
Hello!
I'm new to Vala and I'm trying to figure out if it meets the following
requirements:
- Bindings to C or other mainstream language (to have some code base, like
hashset)
- Some trivial memory management and decent sytax
- Way to work with unmanaged objects, which is very important
I have looked into manual of it and can't find a clear answer to these
questions, can I have such object:
- Allocation and deallocation is fully manual - I can alloc arbitrary amount
of memory to that object and work with it in whichever way I choose.
- No additional data will be added to it ([Compact] struct?).
- Allocating this object will just request memory and not fill it with zeros
or do other operations (often this would be 1/3 of total time needed to
create an object, except what OS does).
- I can cast this object to something, what has some interface and methods
(which are then capable to work with this* pointer).
I did look at code compiled by Vala and saw the following at initialization:
public static unowned AltStruct a() {
unowned AltStruct a = AltStruct();
return a;
}
Compiles into:
void demo_hello_world_a (AltStruct* result) {
AltStruct a = {0};
memset (&a, 0, sizeof (AltStruct));
*result = a;
return;
}
This is:
AltStruct a = {0};
memset (&a, 0, sizeof (AltStruct));
As much as I understand, this would first initialize it with a zero-value
(it contains one int) and then fill it's memory area with zeroes?
Could I write code, which compiles into:
void demo_hello_world_a (AltStruct* result) {
AltStruct a;
*result = a;
return;
}
And, moreover, could I write code, which compiles into:
void demo_hello_world_a (AltStruct* result) {
int i = 7;
AltStruct* a;
a = calloc(1, sizeof(a));
*result = a;
return;
}
And, as a side-question, is this "AltStruct* result" compiled into exactly
the same code (as fast as) as if the function did return a result? Probably
is?
Tambet
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]