delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/09/12:25:49

From: cbraga AT datasoft DOT com DOT br
Message-ID: <B0000048269@datasoft.datasoft.com.br>
To: "Erik Max Francis" <max AT alcyone DOT com>
Cc: "djgpp list" <djgpp AT delorie DOT com>
Subject: Re: DJGPP Structs
Date: Sun, 9 Mar 1997 13:39:17 -0300
MIME-Version: 1.0

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019