Re: [Vala] Array of structs OR Array of classes
- From: JM <interflug1 gmx net>
- To: Vala ML <vala-list gnome org>
- Subject: Re: [Vala] Array of structs OR Array of classes
- Date: Sun, 08 Nov 2009 11:58:39 +0100
Hi Jan
Thanks for reply!
This raises a few more questions for me:
Would there be an advantage/disadvantage for me to use classes instead
of structs? I need no additional features of these classes.
Depends on the size of the structures and number of reallocations (due to
extending the array). If the structure is small (yours seems to be), the copy
will be faster than the allocation, so structures will be better. If they get
bigger, the copy time will start to grow and classes start to be better.
My structs look like this:
public struct MyData {
public string A;
public string B;
public string C;
public string D;
public uint E;
public uint F;
public int G = 0;
public string H;
public string I;
}
Is this a small structure in your understanding?
The reallocations are coming only from extending the array when I append
new MyData structures. I'm using arrays with typically between 20 and
500 members.
So basically, this a comparison of the copy time when passing on the
array and the allocation time for the classes when creating the array,
right?
The array also uses up to twice the memory you need, because it's allocated
in powers of two.
Why do arrays use twice the memory I need?
If I use the compact classes as a replacement for the structs, do I have
to set each array member and the array itself to null after usage. Or is
there some kind of memory management for these kind of classes? Or
better use classes that are not compact but do not inherit from
GLib.Object?
Regards
Jörn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]