Subject: Changes to libs/Graphics.c

From: [email-masked] (Paul D. Smith)
Date: Fri, 12 Mar 1999 11:17:24 -0500

Hi Steve; I note in your change to libs/Graphics.c you added:

  XSegment* seg = (XSegment*)safemalloc(sizeof(XSegment) * line_width);

but you never free this; ouch :)

On this topic, I wonder if we've ever considered using alloca()?  It can
really help reduce heap rot and increase the flexibility of the apps
(because programmers don't have to worry about memory leaks they're more
likely to use alloca() instead of just declaring a fixed-size buffer to
avoid malloc()).

Typically what happens is you ship an alloca.c along with the app which
provides a "dummy alloca" function, which still works on _almost_ all
systems (it works on all systems with a stack that increases
consistently in one direction (either direction) as you get deeper in
the function call hierarchy) for those compilers which don't support
alloca().  Actually, alloca() is surprisingly wide-spread now; AIX's
compiler, Sun's compiler, etc. provide it, in addition to GCC of course.
I do this with GNU make, which runs on UNIX, VMS, DOS, Windows, and
Amiga and I've only ever received one complaint from someone with a
_really_ strange system.

On the other hand, I'm not really widely familiar with the code so I
can't say how often we actually tend to allocate this temporary buffers
which only have function scope (that is, they disappear when the
function exits).

I like alloca() a lot, myself, but YMMV.

Thoughts?

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[email-masked]>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Steve Robbins <[email-masked]>
Date: Sat, 13 Mar 1999 08:22:25 -0500 (EST)

> but you never free this; ouch :)

How embarrassing!  Ouch indeed --- and thanks to the Hippo for quickly
fixing this.

> On this topic, I wonder if we've ever considered using alloca()?

Yep, someone has!  I discovered an alloca() call last night --- in
FvwmPager/x_pager.c --- because it doesn't compile with SGI's cc.

[Having everyone developing with gcc (which, among other things, supplies
alloca) can be a drawback for portability, it seems ;-)]

> It can

[ ... ]

> I like alloca() a lot, myself, but YMMV.

It sounds good to me, though I'm not familiar enough with the code,
either, to know if it is widely useful.  I do know that if we *don't*
provide it, we need to make one more malloc() call for a function-scoped
variable!