From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agsw6-0004yw-90 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 07:51:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agsw1-0004GX-9q for qemu-devel@nongnu.org; Fri, 18 Mar 2016 07:51:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agsw1-0004GQ-4I for qemu-devel@nongnu.org; Fri, 18 Mar 2016 07:51:17 -0400 References: <1458057598-11041-1-git-send-email-dhannawatpooja1@gmail.com> <20160317145025.GN14062@stefanha-x1.localdomain> <56EB34A7.9030601@redhat.com> From: Paolo Bonzini Message-ID: <56EBEBAF.2090108@redhat.com> Date: Fri, 18 Mar 2016 12:51:11 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4] socket: Allocating Large sized arrays to heap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pooja Dhannawat Cc: Stefan Hajnoczi , qemu-devel@nongnu.org On 18/03/2016 12:24, Pooja Dhannawat wrote: > > > On Fri, Mar 18, 2016 at 4:20 AM, Paolo Bonzini > wrote: > > > > On 17/03/2016 16:31, Pooja Dhannawat wrote: > > > > > > On Thu, Mar 17, 2016 at 8:20 PM, Stefan Hajnoczi > > >> wrote: > > > > On Tue, Mar 15, 2016 at 09:29:58PM +0530, Pooja Dhannawat wrote: > > > @@ -170,8 +170,8 @@ static void net_socket_send(void *opaque) > > > s->index = 0; > > > s->packet_len = 0; > > > s->nc.link_down = true; > > > - memset(s->buf, 0, sizeof(s->buf)); > > > > This change is unrelated to allocating buf1 on the heap. What is the > > purpose of this line? > > > > > > I moved buf from stack to Heap, used g_new(), but I got your point if we > > need to initialize it with 0 then I have to keep that one. > > > > Other wise doing so it gets whatever garbage it has already. > > This is s->buf, not buf. Also, the BiteSizedTasks page says "Make the > stack array smaller and allocate on the heap in the rare case that the > data does not fit in the small array". > > So here, should I check with stack consumption(size of array) and if it > is greater than accepted level, then only keep on heap? If it is greater than the accepted level, the on-stack buffer is not used and you allocate one that has the right size on the heap. Paolo > If no, Can you please help me with this one? > > Paolo > >