gmail seems to not do a reply-to-all this evening. Bah. ---------- Forwarded message ---------- From: Jon Masters <jonmasters@xxxxxxxxx> Date: Oct 23, 2005 10:45 PM Subject: Re: memory and function pointer problem To: Rik van Riel <riel@xxxxxxxxxxx> On 10/22/05, Rik van Riel <riel@xxxxxxxxxxx> wrote: > On Sat, 22 Oct 2005, gaurav sharma wrote: > > > p = malloc(500*sizeof(int)); > > > for(i=0;i<512;i++) { > > printf("p[%d]: %d\n",i,p[i]); > > } > > Can someone please explain why this is happening.I am using gcc4 > > compiler on 2.6 linux kernel. Shouldn't it give seg fault. I read that > > accessing more memory than allocated results in seg fault. > > Memory for processes is allocated on a page size (4kB) > granularity. I suspect there is some space left in the > page, beyond the size of your array. Additionally, glibc's malloc will allocate memory in buckets according to its own internal algorithms and will use some of that memory for accounting overhead. I'm not entirely familiar with exactly what it uses these days, but I wouldn't go accessing anything beyond what you specifically allocated in case you just overwrote the tables being used internally for tracking allocation. Jon. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/