Date: Sun, 15 Jun 1997 16:57:34 -0400 (EDT) From: Michael Phelps To: Jawed Karim cc: djgpp AT delorie DOT com Subject: Re: DJGPP MEM BUG? In-Reply-To: <33A36EAE.17D4@tc.umn.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Sat, 14 Jun 1997, Jawed Karim wrote: > I really need the following code to work. Under Linux, this works > PERFECTLY. Under DJGPP I get SIGSEVs every single time. See for > yourself: > > Exiting due to signal SIGSEGV > Stack Fault at eip=00001559 > eax=00000000 ebx=0004c100 ecx=00000000 edx=0000033e esi=00000054 > edi=0000a2d4 > ebp=0004a2a8 esp=fffcaaa8 program=D:\JAW3D\A.EXE > cs: sel=00a7 base=82e4e000 limit=0005ffff > ds: sel=00af base=82e4e000 limit=0005ffff > es: sel=00af base=82e4e000 limit=0005ffff > fs: sel=0087 base=0000cfc0 limit=0000ffff > gs: sel=00bf base=00000000 limit=ffffffff > ss: sel=00af base=82e4e000 limit=0005ffff > --------- > It doesnt crash with [255][32] but it does with [255][64]. In any case, > even with 128 it SHOULD NOT. It's not that much memory, and under linux > gcc it works. Any ideas? Please email me directly... > When you declare an automatic variable, the space for it is allocated on the stack (256K by default). So, if the variables require more space then that, you need to either stubedit the executable file to increase the default stack space, or dynamically allocate it, as I have done to your program below. > -- > #include #include > > typedef struct { > int r, g, b; > int closest_fit; > } Table; > > main() > { > /* Table thingy[255][128]; */ Table **thingy; int x; thingy = (Table **)malloc(255 * sizeof(Table *)); if (thingy == NULL) { fprintf(stderr, "Unable to allocate sufficient memory.\n"); exit(1); } for (x = 0; x < 255; x++) { thingy[x] = (Table *)malloc(128 * sizeof(Table)); if (thingy[x] == NULL) { fprintf(stderr, "Insufficient memory.\n"); exit(1); } } /* now you can use thingy the way you wanted to */ return 0; /* main returns an int */ > } > --- > Jawed Karim > jawed AT tc DOT umn DOT edu > http://umn.edu/~jawed > ---Michael Phelps morphine AT cs DOT jhu DOT edu CH3 | N / | ______/ | / \ CH2 _____/ \__|__ // \\ / | \\ // \\______/___CH2 \\ \ / \ / \______/ \_____/ / ------ \ / \ OH \ / OH O Morphine