From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 9 14:52:08 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2753B106566C for ; Fri, 9 Apr 2010 14:52:08 +0000 (UTC) (envelope-from alexanderchuranov@gmail.com) Received: from mail-gw0-f54.google.com (mail-gw0-f54.google.com [74.125.83.54]) by mx1.freebsd.org (Postfix) with ESMTP id D20A18FC12 for ; Fri, 9 Apr 2010 14:52:07 +0000 (UTC) Received: by gwaa12 with SMTP id a12so1980769gwa.13 for ; Fri, 09 Apr 2010 07:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type; bh=WFrjS3Anrer7Hjn6B/u9ZtdOCOvVD7cfAxEwRjt6pi4=; b=rkNzMuwigzAe5lCL0kClr00LfKgU26a6foln1YnBc0G0AxND4OWnrnKD1AXL7ts6dj i3okiI4HzS4giCTvOHaRelStbsqdixSn5hi0t0SORTQeUcL+5BhCIbKd1Y+0qSeZoTr4 e26vO7kY1zds5QeNJ6HB5WEE3g7YVdqKj5StU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=HIJFRwVI6oXgz2coPc45NNFvyHn29Yy5Lmue0MkDPoWdPv5yirf6JmFwydZhViPrT6 WjKnXj31fngGr43x2+W0tuq6oXzP6UC0L8tIRQtL0KeIrwls/hyBzTAOOXhpQaoAp1W3 VBuQbrqamxNTWU+zM7L+vQq1zZc032injGWWg= MIME-Version: 1.0 Received: by 10.90.119.15 with HTTP; Fri, 9 Apr 2010 07:52:04 -0700 (PDT) In-Reply-To: References: Date: Fri, 9 Apr 2010 18:52:04 +0400 Received: by 10.91.31.6 with SMTP id i6mr76789agj.116.1270824727083; Fri, 09 Apr 2010 07:52:07 -0700 (PDT) Message-ID: From: Alexander Churanov To: Leinier Cruz Salfran Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers Subject: Re: c question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Apr 2010 14:52:08 -0000 2010/4/9 Leinier Cruz Salfran > - 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