[comp.sys.sun] Sparcstation problems with malloc

torgerse@udel.edu, , torger@uncecs.edu (Todd Torgersen) (10/12/89)

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) ;

   }

}

ozkan@vuse.vanderbilt.edu (Mehmed Ozkan) (10/15/89)

>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

This is what happens if i run your program on our SPARCstation, which has
its own disk.

Mehmed Ozkan
Vanderbilt University.

ozkan@vuse.vanderbilt.edu

"sp.c" [New file] 41 lines, 781 characters 
<32>[try] % make sptest
cc    -sun4 -o sp sptest.c 
<33>[try] % sptest
Enter n :200000
sp: count = 0
sp: count = 1000
 .
 .
 .
sp: count = 193000
sp: count = 194000
sp: count = 195000
sp: count = 196000
sp: count = 197000
sp: count = 198000
sp: count = 199000