Date: Fri, 9 Apr 2010 18:52:04 +0400 From: Alexander Churanov <alexanderchuranov@gmail.com> To: Leinier Cruz Salfran <salfrancl.listas@gmail.com> Cc: freebsd-hackers <freebsd-hackers@freebsd.org> Subject: Re: c question Message-ID: <x2z3cb459ed1004090752q70f6315fqb53ba36d26ce9c12@mail.gmail.com> In-Reply-To: <l2ga2585ef1004090709u821fc979i226a3125d9da8251@mail.gmail.com> References: <l2ga2585ef1004090709u821fc979i226a3125d9da8251@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
2010/4/9 Leinier Cruz Salfran <salfrancl.listas@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?x2z3cb459ed1004090752q70f6315fqb53ba36d26ce9c12>