Mail Archives: djgpp/1997/03/09/12:25:49
> From: Erik Max Francis <max AT alcyone DOT com>
> 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
- Raw text -