home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / sun / misc / 6042 < prev    next >
Encoding:
Text File  |  1992-12-29  |  5.5 KB  |  182 lines

  1. Xref: sparky comp.sys.sun.misc:6042 comp.unix.solaris:442 comp.unix.misc:4758
  2. Path: sparky!uunet!noc.near.net!news.centerline.com!matt
  3. From: matt@centerline.com (Matt Landau)
  4. Newsgroups: comp.sys.sun.misc,comp.unix.solaris,comp.unix.misc
  5. Subject: mallopt() a no-op in SunOS 4.1.x?
  6. Date: 29 Dec 1992 20:53:06 GMT
  7. Organization: CenterLine Software, Inc.
  8. Lines: 169
  9. Distribution: inet
  10. Message-ID: <1hqdriINNh67@armory.centerline.com>
  11. NNTP-Posting-Host: 140.239.1.32
  12.  
  13. Can anyone either verify or refute the observation that mallopt, although 
  14. it's present in the C library, seems to be a no-op in SunOS 4.1.x?
  15.  
  16. Compiling and running the attached program on a variety of systems -- an
  17. HP/700 running HP/UX 8, a sparc running SunOS 4.1.1, and a sparc running 
  18. Solaris 2.1 -- suggests that mallopt actually has some effect in HP/UX 
  19. and in Solaris, but no effect at all in SunOS 4.
  20.  
  21. Run the program with no arguments to allocate 10 blocks and print their
  22. addresses.  Then run it again with the arguments "-s 256", to make a 
  23. call to mallopt(M_MXFAST, 256) on startup.  Observe that on the HP and
  24. Solaris 2.1 platforms, the addresses you get back from malloc will be
  25. different than in the no-arguments case, and that the mallinfo structure
  26. will claim that malloc is actually using the small block allocation 
  27. scheme.
  28.  
  29. Under SunOS 4, however, the addresses returned from malloc are the same
  30. whether or not mallopt is used, and although mallinfo claims that some
  31. small blocks have been allocated, this seems to be a lie, and there is
  32. no evidence anywhere else in the mallinfo structure that small blocks 
  33. are being used.
  34.  
  35. So, can anyone who has access to the SunOS 4.1 version of malloc verify
  36. that mallopt is, in fact, doing nothing except causing some fields in
  37. the mallinfo structure to be incremented?  Or is there some bug in the
  38. mallopt usage in my test program?  Any clues?
  39. --
  40.  Matt Landau            Waiting for a flash of enlightenment
  41.  matt@centerline.com              in all this blood and thunder
  42.  
  43.  
  44. ---------------  cut here for mallopt test program ---------------------
  45.  
  46. #include <stdio.h>
  47. #include <malloc.h>
  48.  
  49. typedef struct mallinfo    m_info;
  50.  
  51. /* 
  52.  * You may want to compile with -Dcomplete for SunOS 4.1.x, where the
  53.  * mallinfo structure has a few extra fields.
  54.  */
  55.  
  56. #if complete
  57.  
  58. #define MINFO_FORMAT "\
  59. total arena size = %d\n\
  60. number of ordinary blocks = %d\n\
  61. number of small blocks = %d\n\
  62. number of holding blocks = %d\n\
  63. space in holding block headers = %d\n\
  64. space in small blocks in use = %d\n\
  65. space in free small blocks = %d\n\
  66. space in ordinary blocks in use = %d\n\
  67. space in free ordinary blocks = %d\n\
  68. cost of enabling keep option = %d\n\
  69. max size of small blocks = %d\n\
  70. number of small blocks in a holding block = %d\n\
  71. small block rounding factor = %d\n\
  72. space (including overhead) allocated in ord. blocks = %d\n\
  73. number of ordinary blocks allocated = %d\n\
  74. bytes used in maintaining free tree = %d\n"
  75.  
  76. #else
  77.  
  78. #define MINFO_FORMAT "\
  79. total arena size = %d\n\
  80. number of ordinary blocks = %d\n\
  81. number of small blocks = %d\n\
  82. number of holding blocks = %d\n\
  83. space in holding block headers = %d\n\
  84. space in small blocks in use = %d\n\
  85. space in free small blocks = %d\n\
  86. space in ordinary blocks in use = %d\n\
  87. space in free ordinary blocks = %d\n\
  88. cost of enabling keep option = %d\n"
  89.  
  90. #endif
  91.  
  92. /* getopt stuff.  why isn't this in a header file? */
  93.  
  94. extern char *optarg;
  95. extern int optind, opterr;
  96.  
  97.  
  98. main(ac, av)
  99. int ac;
  100. char **av;
  101. {
  102.     int        opt;
  103.     int        mallopt_size  = -1;
  104.     int        mallopt_grain = -1;
  105.     char *    ptr;
  106.     m_info    mi;
  107.     int        n;
  108.  
  109.     while ((opt = getopt(ac, av, "s:g:")) != -1)
  110.     {
  111.     switch(opt)
  112.     {
  113.       case 's':
  114.         mallopt_size = atoi(optarg);
  115.         break;
  116.  
  117.       case 'g':
  118.         mallopt_grain = atoi(optarg);
  119.         break;
  120.  
  121.       default:
  122.         fprintf(stderr, "usage: %s [-s opt_size] [-g opt_grain]\n", av[0]);
  123.         exit(1);
  124.     }
  125.     }
  126.  
  127.     
  128.     if (mallopt_size > 0)
  129.     {
  130.     if (mallopt(M_MXFAST, mallopt_size) != 0)
  131.         fprintf(stderr, "Could not mallopt(M_MXFAST, %d)\n", mallopt_size);
  132.     else
  133.         fprintf(stderr, "Mallopt size set to %d\n", mallopt_size);
  134.     }
  135.     
  136.     if (mallopt_grain > 0)
  137.     {
  138.     if (mallopt(M_GRAIN, mallopt_grain) != 0)
  139.         fprintf(stderr, "Could not mallopt(M_GRAIN, %d)\n", mallopt_grain);
  140.     else
  141.         fprintf(stderr, "Mallopt grain set to %d\n", mallopt_grain);
  142.     }
  143.     
  144.  
  145.     for (n = 0 ; n < 5 ; n++)
  146.     {
  147.     ptr = malloc(10);
  148.     fprintf(stderr, "malloc(10)   = 0x%0x\n", ptr);
  149.     }
  150.     for (n = 0 ; n < 5 ; n++)
  151.     {
  152.     ptr = malloc(128);
  153.     fprintf(stderr, "malloc(128) = 0x%0x\n", ptr);
  154.     }
  155.     
  156.     mi = mallinfo();
  157.     
  158.     fprintf(stderr, MINFO_FORMAT, 
  159.         mi.arena,              /* total space in arena */               
  160.         mi.ordblks,           /* number of ordinary blocks */          
  161.         mi.smblks,            /* number of small blocks */             
  162.         mi.hblks,             /* number of holding blocks */           
  163.         mi.hblkhd,            /* space in holding block headers */     
  164.         mi.usmblks,           /* space in small blocks in use */       
  165.         mi.fsmblks,           /* space in free small blocks */         
  166.         mi.uordblks,          /* space in ordinary blocks in use */    
  167.         mi.fordblks,          /* space in free ordinary blocks */      
  168.         mi.keepcost          /* cost of enabling keep option */
  169. #if complete
  170.         ,
  171.         mi.mxfast,            /* max size of small blocks */          
  172.         mi.nlblks,            /* number of small blocks in a holding block */
  173.         mi.grain,             /* small block rounding factor */
  174.         mi.uordbytes,         /* space (including overhead) allocated in ord. blocks */
  175.         mi.allocated,         /* number of ordinary blocks allocated */
  176.         mi.treeoverhead           /* bytes used in maintaining free tree */
  177. #endif
  178.         );
  179.         
  180. }
  181.  
  182.