From: swanger@news.duc.auburn.edu
Newsgroups: news.software.nntp
Subject: Help wanted with slow program
Date: 14 Sep 92 18:47:13 GMT
Organization: Auburn University, AL

I am writing an NNTP based newsreader in C for my SUN IPC (SUNOS 4.1.2 with
NNTP 1.5.11 client software).  What I have works pretty well so far.  My
complaint is, it runs kind of slowish when I open a group and load all of
the subjects for the group's articles into an array of character strings. 
At least, it seems slow to me (25-45 seconds for a group with over 300
articles in it).  I use the XHDR command to load the subjects into the
array.  Is this slowness caused by:

- xhdr having to search the header of each article file for the info
- network bandwidth problem
- the server is slow
- crummy programming on my part

For whats its worth, when I load all of the group names into an array of
strings at program startup, it only takes about 2 seconds and we have nearly
2000 groups on our server.  Anyway, here is the function that reads in the
subjects for each article.  I wanted to also load more info about each
article in a group, but I don't know if I have the patience.

If any of you can see a way to speed up this routine, I would be very
grateful.

------------------------------------------------------------------------------

/*  call this routine after opening group.  num, first_article and      */
/*  last_article returned when group was opened                         */

char **get_articles(num, first_article, last_article, real_num)
int num, first_article, last_article, *real_num;
{
   int loop, finished, response;
   char **articles, string[NNTP_MAX];  /* NNTP_MAX is 512 */
 
   finished = FALSE;
 
/*  allocate array of points for article names (subjects)              */
/*  sizeof_charp = sizeof(char *);  and is called at the start         */
/*  of the program (used several times in the program, trying to       */
/*  speed things up                                                    */

   articles = (char **) malloc(num * sizeof_charp); 
   if (articles == NULL)
   {
      return(NULL);
   }

/*  create xhdr string to send to server                               */

   sprintf(string,"xhdr subject %ld-%ld", first_article, last_article);
 
   put_server(string);
 
/*  allocate string to receive response from server                    */

   articles[0] = (char *) malloc(NNTP_MAX * sizeof_char);
 
   if (get_server(articles[0], NNTP_MAX) < 0)
   {
      printf("\n%s\n\n", ERROR2);
      exit(0);   
   }

/*  strip response code from server response                          */

   response = get_response(articles[0]);
   if (response != OK_HEAD)
   {
      return(FALSE);
   }
 
   loop = 1;
   while (finished == FALSE)
   {

/*  read each subject into string and allocate space in articles      */

      if (get_server(string, NNTP_MAX) < 0)
      {
         printf("\n%s\n\n", ERROR2);
         exit(0);   
      }
      else
      {
         if (strcmp(string, ".") == 0)
         {
            finished = TRUE;
         }
         else
         {
            articles[loop] = (char *) malloc((strlen(string)+1) * sizeof_char);
            strcpy(articles[loop], string);
            loop++;
         }
      }
   }
   *real_num = loop;
   return(articles); 
}

------------------------------------------------------------------------------

I would appreciate any help you could send.  Thanks!
-- 
David Swanger,   Auburn University, Alabama,   swanger@ducvax.auburn.edu 
Xref: sparky news.software.nntp:1132 news.software.b:2914