From: Ian Jackson Subject: Re: [PATCH 10/31] libxl: Crash (more sensibly) on malloc failure Date: Wed, 11 Apr 2012 12:21:24 +0100 Message-ID: <20357.26932.161008.384380@mariner.uk.xensource.com> References: <1334084885-14474-1-git-send-email-ian.jackson@eu.citrix.com> <1334084885-14474-11-git-send-email-ian.jackson@eu.citrix.com> <1334134921.5394.78.camel@zakaz.uk.xensource.com> <20357.23514.59542.527454@mariner.uk.xensource.com> <1334141224.5394.106.camel@zakaz.uk.xensource.com> <20357.25912.898502.188820@mariner.uk.xensource.com> <1334142894.5394.125.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1334142894.5394.125.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("Re: [Xen-devel] [PATCH 10/31] libxl: Crash (more sensibly) on malloc failure"): > On Wed, 2012-04-11 at 12:04 +0100, Ian Jackson wrote: > > NB that libxl__ptr_add needs to be rewritten not to be quadratic in > > the number of pointrs added (!) > > Isn't it O(N) in numbers of pointers? Yes, each addition is O(N). Adding N pointers is O(N^2). > I also just noticed that the initial: > /* fast case: we have space in the array for storing the pointer */ > for (i = 0; i < gc->alloc_maxsize; i++) { > if (!gc->alloc_ptrs[i]) { > gc->alloc_ptrs[i] = ptr; > return 0; > } > } > is a bit suboptimal since we never remove a ptr from the array, so we > may as well track the max actually used. Then the fast path might > actually be fast... I thought we used to have a function for removing pointers from the gc but I see that it has gone. So yes this could be rewritten fairly simply. Ian.