From: cbraga AT datasoft DOT com DOT br Message-ID: To: "Erik Max Francis" Cc: "djgpp list" Subject: Re: DJGPP Structs Date: Sun, 9 Mar 1997 13:39:17 -0300 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit > From: Erik Max Francis > Cristovao Braga wrote: > > #define max_x 25 > > #define max_y 25 > > > > defPt *View; > > > > View = (defPt *) malloc (sizeof (defPt) * max_x * max_y); > > *(View + x + y * max_x) = 25; [*] > > Yes: "incompatible types in assignment" (directly from gcc). > > I don't know what the statement marked with [*] is supposed to do here. I know, I was sleeping when I wrote that. :-) You can stop the warnings by casting the pointer: (defPt *)(View + x + y * max_x) = ... And linear space memory is what I want. Why? 1. It is a lot simpler to deal with, A _L_O_T_. 2. Did you know each pointer eats 4 bytes? 3. It is faster, 4. Allocating a single big chunk instead of lots of little bits reduces memory fragmentation to insignificant dimensions, 5. Did I say it's faster? > This is (along the lines of) the right way to do dynamic allocation if you If there's anything wrong, would you (or anyone) mind telling me? Regards, Cristovao Braga. > want to treat memory as a linear space. If you want, however, to treat it > as truly a two-dimensional array, then you have to do as I've posted just > recently on this group: First, allocate an array of max_x defPt pointers, > and then for each of those max_x pointers, allocate an array of max_y > defPts. > > Erik Max Francis, &tSftDotIotE / email: max AT alcyone DOT com