Sparcstation problems with malloc

torgerse at udel.edu torgerse at udel.edu
Thu Oct 12 07:43:00 AEST 1989


We recently got two SPARCstation 1 workstations and found a problem
building very long linked lists with "malloc".   The following program
crashes our SPARCstations when n=200000

The program runs fine on the sun - 4/110's and also on our host (a sun - 4
/ 280).  Has anyone out there experienced this ?  Does anyone have a clue
why the machine crashes ?   When this program is run on other sun-4's (not
SPARCstations) it will do the sensible thing when n exceeds the available
memory.  On a SPARCstation, the machine crashes long before the memory
limit is approached.  All machines here are diskless except the server.

Thanks in advance for your help.   Todd
                                   (919) 759-5536
#include <stdio.h>
#define CHECKIT 1000

main(argc,argv)
int argc ;
char * argv[] ;

{

struct block {
   int data ;
   struct block * next ;
} blk ;

struct block *temp ;
struct block *list ;
int count,flag,n ;

/*  begin executable code.  */
   list = NULL ; flag = (0==0) ; count = 0 ;
   printf("Enter n : ") ;
   scanf( "%d", &n ) ;
   while ( (count < n) && flag ) {
        temp = list ;
        list = (struct block *)  malloc( sizeof(blk) ) ;
        flag = (NULL != list) ;
        if (flag) {
          if ( 0 == (count % CHECKIT)) 
            printf("%s: count = %d\n",argv[0],count) ;
          list->data = count ;
          list->next = temp ;
          ++count ;
        }
        else 
          printf("malloc returns NULL with count = %d\n",count) ;

   }

}



More information about the Comp.sys.sun mailing list