cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/09/19:20:57

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP Structs
Date: Sun, 09 Mar 1997 13:30:29 -0800
Organization: Alcyone Systems
Lines: 51
Message-ID: <33232BF5.3197CADD@alcyone.com>
References: <B0000048269 AT datasoft DOT datasoft DOT com DOT br>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

cbraga AT datasoft DOT com DOT br wrote:

> > > 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) = ...

No, you're getting the warning because you're trying to assign an integral
type to a defPt.  In fact, this works less, because you're now trying to
assign an integral type to a defPt *.

What you meant is 

    View[x + y*max_x].sx = 25 /* or whichever member you meant */;

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

With the two-dimensional array method, you have a pointer add, a
dereference, a pointer add, and a dereference.  With the one-dimensional
method, you have an integer multiply, two pointers adds, and a dereference.

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

You weren't using the right syntax for what you meant again.

-- 
       Erik Max Francis, &tSftDotIotE / email:  max AT alcyone DOT com
                     Alcyone Systems /    web:  http://www.alcyone.com/max/
San Jose, California, United States /    icbm:  37 20 07 N  121 53 38 W
                                   \
              "I am become death, / destroyer of worlds."
                                 / J. Robert Oppenheimer (quoting legend)

- Raw text -


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