From: G DOT DegliEsposti AT ads DOT it To: djgpp AT delorie DOT com Message-ID: Date: Thu, 8 Jan 1998 09:44:58 +0100 Subject: Re: problem with memory allocation (I think) Mime-Version: 1.0 Content-type: text/plain; charset=us-ascii Precedence: bulk >I am getting a runtime error when running my program. Here is the >part that is not running correctly: > > long i; > unsigned int *buffer; > buffer = malloc(640 * 480 * 2); > > for(i = 0; i < 640*480; i++) > { > buffer[i] = i; > } [...] > >If I change the for loop so that it only loops 640*480/2 times, then >it works fine. Can anyone tell me what's going on? You malloc 640 * 480 * 2 bytes, but you are accessing 640 * 480 ints, but djgpp is a 32 bit compiler, so you need 640 * 480 * 4 bytes to allocate them all. If you access 640 * 480 / 2 ints then you are accessing all the memory you allocate and you have no sigsegv. ciao Giacomo