c question
Alexander Churanov
alexanderchuranov at gmail.com
Fri Apr 9 14:52:08 UTC 2010
2010/4/9 Leinier Cruz Salfran <salfrancl.listas at gmail.com>
> - use a matrix is faster than use a linked list?
>
> example:
>
> char *szColumnName[10];
> unsigned short iColumnAge[10];
>
>
> struct _llList {
> struct _llList *prev, *next;
> char szName[64];
> unsigned short iAge;
> };
Leinier ,
This depends on what kind of operations are performed. For sequential
traversing, both are very appropriate. However, you can not perform a binary
search on a list. You also can not combine two arrays into a single one with
constant complexity.
Lists also have greater memory overhead for small structures.
My advice: always use arrays.
Use lists if:
1) Copying items when the dynamic arrays grows is inappropriate.
2) List-specific operations like O(1) splicing or O(1) insertions and
deletions are required.
Alexander Churanov
More information about the freebsd-hackers
mailing list