Newsgroups: comp.sys.sgi
Subject: A titbit about the FM & Irix 4.0.5 (and a question)
From: tim@resmel.bhp.com.au (Tim Monks)
Date: 14 Sep 92 16:45:12 +1000
X-Newsreader: Tin 1.1 PL5

Whilst trying to improve the efficiency of some horrible code I had
written, I discovered the following titbit about the font manager (which
may be of interest to other developers using the FM library).  Some of
you may recognise the origins of this code snippet from Mark Overmars'
FORMS library.  The timings are for a medium loaded 340VGX running Irix
4.0.5.

-----8<----------------------------------------------------
#include <stdio.h>
#include <malloc.h>
#include <fmclient.h>

main(void)
{
    /* 
       Compile with:
	   cc -g -o foo foo.c -lmalloc -lfm_s -lgl_s
    */
    static fmfonthandle thefont[5], smallfont[5], normalfont[5], largefont[5];
    int             i;

    mallopt(M_DEBUG, 1);	/* this is the statement to watch */
    fminit();
    thefont[0] = fmfindfont("Helvetica");
    thefont[1] = fmfindfont("Helvetica-Bold");
    thefont[2] = fmfindfont("Helvetica-BoldOblique");
    thefont[3] = fmfindfont("Courier");
    for (i = 0; i < 4; i++)
    {
	smallfont[i] = fmscalefont(thefont[i], 8.0);
	normalfont[i] = fmscalefont(thefont[i], 10.0);
	largefont[i] = fmscalefont(thefont[i], 18.0);
    }
}
-----8<----------------------------------------------------

Timing with mallopt:   66.840u 0.460s 1:07.31 99.9% 0+0k 2+0io 0pf+0w
Timing without mallopt: 2.320u 0.320s 0:02.63 100.3% 0+0k 0+0io 0pf+0w
                                      =======
ie: from 67 secs down to 2 secs. 

We have an old 50G running 4.0.1, and the results on that are:
Timing with mallopt:    0.129u 0.429s 0:05.39 10.0% 0+0k 35+0io 25pf+0w
Timing without mallopt: 0.119u 0.409s 0:06.96 7.3% 0+0k 49+0io 29pf+0w

ie: no significant difference in the older Irix 4.0.1.

I suppose these results should not be too suprising, after all the font
manager will be thumping a little of memory, but I have never seen any
other code so dramatically affected by mallopt.  

Now for a little complaint: 
I read the release notes for 4.0.5 fairly well (imho) and the only
mention I saw on the font manager and memory allocation was 12-3: "The
IRIS FM now allocates memory differently, so the functions fmcachelimit,
..  are no longer needed." Not much of a hint there of any other
consequences of the change.  In defence of SG, the manual page for
malloc(3X) says that with M_DEBUG on, "...the performance of malloc is
reduced considerably." (but heck, the code the above snippet came from,
has been mutating over a year; I read the manual page for mallopt
several months ago when I was chasing malloc problems, and took no
notice of the warning.)


Now the question:
I have some code (pure gl, many windows) and I want fancy text in each
of them.  Is it completely safe to do all the fminit, fmfindfont's and
fmscalefont's ONCE ONLY at the start of the program before any windows
get opened, and then use the appropriate handles in all the different
windows, or should I use separate font initialisations for each window ?
(what I want to know is: is there any interaction between the GL
transformation matrices and the page matrices that I should know about ?)

I will post the definite answer to this if I receive one.


--
Dr Tim Monks
Exploration Group                      | (direct)   (+61-3)566-7448
BHP Research - Melbourne Laboratories  | (switch)   (+61-3)560-7066
245 Wellington Rd, Mulgrave, 3170,     | (fax)      (+61-3)561-6709
AUSTRALIA                              | (internet) tim@resmel.bhp.com.au