Mail Archives: djgpp/1998/01/08/03:45:47
>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
- Raw text -