aboutsummaryrefslogblamecommitdiff
path: root/documentation/manual-pages/ja/man3/malloc.3
blob: 24daede2389a736268f1e2f701162120eae2fcfb (plain) (tree)



































                                                                              
                                                                                   
             
   

                   
   
        
                                               
                                      

              
        
            






















                                                                  
                                                               
          








                                          






                                        

                                                               










                                                  

                                                  


                                                    

                
       
                                            
       


            









                                                              


                 










                                                


                                





















                                                                          
                                                       
                      
                    

                













                                                                          

                                                                          







                                                  







                                                          



                                    
                                                                        








                                                              
         













                                                        
                                                 

                                                                          
                                      





























                                                                
                                    




                                                
   



          







                                                              



            
                                  
       



                                                      


                                                      




                                  




                           


                                                              
                                                          
                          
                                                  


                                                                

                                                  

                                                        
                              
                                                
                                        
   
   

                                                                    






                                                                    
                                                          







                                                                  

                                                                     



                                                          
                                                














                                                                        


                                                                        





                            
                                                         
                                          





                                                                  

                                



                                                            
                                  

                                                            
                           
                                


                                                                  

   

                                                                

                                


                            
                       

                                              
                                    

                                                            
                                     



                                          





                                  
                                
                    


                                                                    
                                    


                                                                  
   

            
            









                                         

                  

                              
                                            




                                                                      














                                                                        
.\" Copyright (c) 1980, 1991, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" the American National Standards Committee X3, on Information
.\" Processing Systems.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     @(#)malloc.3	8.1 (Berkeley) 6/4/93
.\" %FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.25.2.14 2001/12/14 18:33:58 ru Exp %
.\" $FreeBSD$
.\"
.Dd August 27, 1996
.Dt MALLOC 3
.Os
.Sh ̾¾Î
.Nm malloc , calloc , realloc , free , reallocf
.Nd ÈÆÍѤΥá¥â¥ê³ä¤êÅö¤Æ¤Î¤¿¤á¤Î´Ø¿ô·²
.Sh ¥é¥¤¥Ö¥é¥ê
.Lb libc
.Sh ½ñ¼°
.In stdlib.h
.Ft void *
.Fn malloc "size_t size"
.Ft void *
.Fn calloc "size_t number" "size_t size"
.Ft void *
.Fn realloc "void *ptr" "size_t size"
.Ft void *
.Fn reallocf "void *ptr" "size_t size"
.Ft void
.Fn free "void *ptr"
.Ft char *
.Va malloc_options;
.Sh ²òÀâ
.Fn malloc
´Ø¿ô¤Ï¡¢
.Fa size
¥Ð¥¤¥È¤Î¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹¡£
³ä¤êÅö¤Æ¤é¤ì¤¿¶õ´Ö¤Ï (²Äǽ¤Ê¥Ý¥¤¥ó¥¿¶¯À©¤Î¸å¤Ç)
¤¢¤é¤æ¤ë¥¿¥¤¥×¤Î¥ª¥Ö¥¸¥§¥¯¥È¤¬Êݸ¤Ç¤­¤ë¤è¤¦¤ËŬÀÚ¤ËÄ´À°¤µ¤ì¤Þ¤¹¡£
¤½¤Î¶õ´Ö¤ÎŤµ¤¬¾¯¤Ê¤¯¤È¤â
.Em pagesize
¥Ð¥¤¥È¤Ç¤¢¤ë¾ì¹ç (
.Xr getpagesize 3
»²¾È)¡¢ÊÖ¤µ¤ì¤ë¥á¥â¥ê¤Ï¥Ú¡¼¥¸¶­³¦¤¬Ä´À°¤µ¤ì¤Æ¤¤¤ë¤³¤È¤Ç¤·¤ç¤¦¡£
.Fn malloc
¤Ë¼ºÇÔ¤¹¤ë¤È¡¢
.Dv NULL
¥Ý¥¤¥ó¥¿¤¬ÊÖ¤µ¤ì¤Þ¤¹¡£
.Pp
Ä̾ï
.Fn malloc
¤¬ÊÖ¤¹¥á¥â¥ê¤Ï¡¢0 ¤Î¥Ð¥¤¥È¤Ç½é´ü²½¤µ¤ì¤Æ¤Ï
.Em ¤¤¤Ê¤¤
¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
.Pp
.Fn calloc
´Ø¿ô¤Ï¡¢
.Fa number
¸Ä¤Î¡¢Ä¹¤µ¤¬
.Fa size
¤Ç¤¢¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ë¶õ´Ö¤ò³ä¤êÅö¤Æ¤Þ¤¹¡£
¤³¤Î´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¤¿·ë²Ì¤Ï¡¢³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤¬ 0 ¤Î¥Ð¥¤¥È¤Ë
ÌÀ¼¨Åª¤Ë½é´ü²½¤µ¤ì¤Æ¤¤¤ë¤³¤È¤ò½ü¤±¤Ð¡¢°ú¿ô
.Dq "number * size"
¤Ç
.Fn malloc
¤ò¸Æ¤Ó½Ð¤·¤¿·ë²Ì¤ÈƱ¤¸¤Ç¤¹¡£
.Pp
.Fn realloc
´Ø¿ô¤Ï¡¢
.Fa ptr
¤Ç»²¾È¤µ¤ì¤ë¡¢°ÊÁ°¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Î¥µ¥¤¥º¤ò
.Fa size
¥Ð¥¤¥È¤ËÊѹ¹¤·¤Þ¤¹¡£
¿·¤·¤¤¥µ¥¤¥º¤È¸Å¤¤¥µ¥¤¥º¤Î¤¦¤Á¡¢
¾®¤µ¤¤Êý¤Î¥µ¥¤¥º¤Þ¤Ç¤Î¥á¥â¥êÆâÍƤÏÊѹ¹¤µ¤ì¤Þ¤»¤ó¡£
¿·¤·¤¤¥µ¥¤¥º¤ÎÊý¤¬Â礭¤¤¾ì¹ç¡¢
¿·¤·¤¯³ä¤êÅö¤Æ¤é¤ì¤¿Éôʬ¤Î¥á¥â¥ê¤ÎÃͤÏ̤ÄêµÁ¤Ç¤¹¡£
Í׵ᤵ¤ì¤¿¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï
.Dv NULL
¤¬ÊÖ¤µ¤ì¤Þ¤¹¤¬¡¢
.Fa ptr
¤¬»²¾È¤¹¤ë¥á¥â¥ê¤ÏÍ­¸ú¤ÇÊѹ¹¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£
.Fa ptr
¤¬
.Dv NULL
¤Ç¤¢¤ë¾ì¹ç¡¢
.Fn realloc
´Ø¿ô¤Ï¡¢»ØÄꤷ¤¿¥µ¥¤¥º¤Î
.Fn malloc
¤ÈƱ¤¸Æ°¤­¤ò¤·¤Þ¤¹¡£
.Pp
.Fn reallocf
´Ø¿ô¤Ï¡¢Í׵ᤵ¤ì¤¿¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¡¢
ÅϤµ¤ì¤¿¥Ý¥¤¥ó¥¿¤ò²òÊü¤¹¤ë¤³¤È¤ò½ü¤±¤Ð¡¢
.Fn realloc
´Ø¿ô¸Æ¤Ó½Ð¤·¤ÈƱ¤¸¤Ç¤¹¡£
¤³¤ì¤Ï
.Fx
¤Ë¸ÇÍ­¤Î API ¤Ç¡¢
.Fn realloc
¤Î½¾Íè·¿¤Î¥³¡¼¥Ç¥£¥ó¥°¥¹¥¿¥¤¥ë¤òÍѤ¤¤ë¤È¡¢
¥é¥¤¥Ö¥é¥ê¤ÎÆâÉô¤Ç¥á¥â¥ê¥ê¡¼¥¯¤ò°ú¤­µ¯¤³¤¹¤È¤¤¤¦
ÌäÂê¤ò¤Ê¤¯¤¹¤¿¤á¤ËÀ߷פµ¤ì¤Þ¤·¤¿¡£
.Pp
.Fn free
´Ø¿ô¤Ï¡¢
.Fa ptr
¤Ç»²¾È¤µ¤ì¤ë³ä¤êÅö¤ÆºÑ¤ß¤Î¥á¥â¥ê¤ò
º£¸å¤Î³ä¤êÅö¤Æ¤Î¤¿¤á¤Ë»ÈÍѤǤ­¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
.Fa ptr
¤¬
.Dv NULL
¤Ç¤¢¤ë¾ì¹ç¡¢²¿¤â¼Â¹Ô¤µ¤ì¤Þ¤»¤ó¡£
.Pp
.Sh Ä´À°
¤³¤ì¤é¤Î¥á¥â¥ê³ä¤êÅö¤Æ¥ë¡¼¥Á¥ó·²¤Î 1 ¤Ä¤¬½é¤á¤Æ¸Æ¤Ó½Ð¤µ¤ì¤ë¤È¤­¤Ë¡¢
¤³¤Î³ä¤êÅö¤Æ¼Â¹Ô¤ÎÆ°ºî¤Ë±Æ¶Á¤òÍ¿¤¨¤ë
¤µ¤Þ¤¶¤Þ¤Ê¥Õ¥é¥°¤¬¥»¥Ã¥È¤â¤·¤¯¤Ï¥ê¥»¥Ã¥È¤µ¤ì¤Þ¤¹¡£
.Pp
.Pa /etc/malloc.conf
¤È¤¤¤¦¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ç»²¾È¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤Î¡Ö̾¾Î¡×¡¢
´Ä¶­ÊÑ¿ô
.Ev MALLOC_OPTIONS
¤ÎÃÍ¡¢
¥°¥í¡¼¥Ð¥ëÊÑ¿ô
.Va malloc_options
¤¬»Ø¤¹Ê¸»úÎó¤Ï¡¢
¤³¤Î½ç½ø¤Ç 1 ʸ»úËè¤Ë¥Õ¥é¥°¤È¤·¤Æ²ò¼á¤µ¤ì¤Þ¤¹¡£
.Pp
¤Û¤È¤ó¤É¤Î¥Õ¥é¥°¤Ï 1 ʸ»ú¤Ç¡¢
Âçʸ»ú¤ÏÆ°ºî¤¬ÀßÄꤵ¤ì¤¿¤³¤È¡¢¤Ä¤Þ¤ê¥ª¥ó¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È¤òɽ¤·¡¢
¾®Ê¸»ú¤ÏÆ°ºî¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¡¢¤Ä¤Þ¤ê¥ª¥Õ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È¤òɽ¤·¤Þ¤¹¡£
.Bl -tag -width indent
.It A
¤¹¤Ù¤Æ¤Î·Ù¹ð
(Íý²ò¤Ç¤­¤Ê¤¤¥Õ¥é¥°¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¤È¤¤¤¦·Ù¹ð¤ò½ü¤¯) ¤ò
Ã×̿Ū¥¨¥é¡¼¤Ë¤·¤Þ¤¹¡£
¤³¤Î¾ì¹ç¡¢¥×¥í¥»¥¹¤Ï
.Xr abort 3
¤ò¸Æ¤Ó½Ð¤·¤Þ¤¹¡£
.It J
.Fn malloc ,
.Fn realloc ,
.Fn reallocf
¤Ë³ä¤êÅö¤Æ¤é¤ì¤ë¿·µ¬¤Î¥á¥â¥ê¡¢Æ±ÍͤË
.Fn free ,
.Fn realloc ,
.Fn reallocf
¤ÇÊÖ¤µ¤ì¤ë¥á¥â¥ê¤Î³Æ¥Ð¥¤¥È¤ò 0xd0 ¤Ë½é´ü²½¤·¤Þ¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï
.Dq R
¥ª¥×¥·¥ç¥ó¤â¥»¥Ã¥È¤·¤Þ¤¹¡£
¤³¤ì¤Ï¥Ç¥Ð¥Ã¥°ÍѤΥª¥×¥·¥ç¥ó¤Ç¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤ÎÄã²¼¤Ë¶¯¤¤±Æ¶Á¤òÍ¿¤¨¤Þ¤¹¡£
.It H
³ä¤êÅö¤Æ´Ø¿ô¤Ç»ÈÍѤµ¤ì¤Æ¤Ê¤¤¥Ú¡¼¥¸¤Ë´Ø¤¹¤ë¥Ò¥ó¥È¤ò¥«¡¼¥Í¥ë¤ËÍ¿¤¨¤Þ¤¹¡£
¥·¥¹¥Æ¥à¤¬²áÅ٤˥ڡ¼¥¸¥ó¥°¤ò¹Ô¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤¬¸þ¾å¤·¤Þ¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¥ª¥Õ¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
.It R
ºÇ½é¤Î³ä¤êÅö¤Æ¤¬½½Ê¬¤ËÂ礭¤¤¾ì¹ç¤Ç¤¢¤Ã¤Æ¤â¡¢
.Fn realloc
´Ø¿ô¤È
.Fn reallocf
´Ø¿ô¤¬¾ï¤Ë¥á¥â¥ê¤ÎºÆ³ä¤êÅö¤Æ¤ò¤¹¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¥á¥â¥ê¤ò°µ½Ì¤¹¤ë¾ì¹ç¤ÎÂ礭¤Ê½õ¤±¤È¤Ê¤ê¤Þ¤¹¡£
.It U
¤¹¤Ù¤Æ¤Î¥ª¥Ú¥ì¡¼¥·¥ç¥ó¤Ç¡¢
.Xr ktrace 1
¤Î¤¿¤á¤Î
.Dq utrace
¥¨¥ó¥È¥ê¤òÀ¸À®¤·¤Þ¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤Î¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢¥½¡¼¥¹¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
.It V
0 ¥Ð¥¤¥È¤ò³ä¤êÅö¤Æ¤è¤¦¤È¤·¤¿¤È¤­¤Ë¡¢
Í­¸ú¤Ê¥Ý¥¤¥ó¥¿¤ÎÂå¤ï¤ê¤Ë
.Dv NULL
¥Ý¥¤¥ó¥¿¤¬ÊÖ¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹
(¥Ç¥Õ¥©¥ë¥È¤ÎÆ°ºî¤Ç¤Ï¡¢ºÇ¾®¤Î³ä¤êÅö¤Æ¤ò¹Ô¤Ã¤Æ¡¢¤½¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤·¤Þ¤¹)¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï System V ¤È¤Î¸ß´¹À­¤Î¤¿¤á¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï
.Dq X
¥ª¥×¥·¥ç¥ó¤ÈŬ¹ç¤·¤Þ¤»¤ó¡£
.It X
³ä¤êÅö¤Æ´Ø¿ô¤Ç¥¨¥é¡¼¤òÊÖ¤¹Âå¤ï¤ê¤Ë¡¢
¿ÇÃÇ¥á¥Ã¥»¡¼¥¸¤ò stderr ¤Ë ɽ¼¨¤·¡¢
(
.Xr abort 3
¤ò»È¤Ã¤Æ)
¥×¥í¥°¥é¥à¤ò core ¤ËÍ¤Þ¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï¡¢¥³¥ó¥Ñ¥¤¥ë»þ¤Ë¡¢
¥½¡¼¥¹¥³¡¼¥É¤Ë°Ê²¼¤òÁȤ߹þ¤à¤è¤¦¤Ë¤·¤ÆÀßÄꤹ¤ë¤Ù¤­¤Ç¤¹¡£
.Bd -literal -offset indent
extern char *malloc_options;
malloc_options = "X";
.Ed
.Pp
.It Z
¤³¤Î¥ª¥×¥·¥ç¥ó¤òÀßÄꤹ¤ë¤È¡¢
.Dq J
¥ª¥×¥·¥ç¥ó¤È
.Dq R
¥ª¥×¥·¥ç¥ó¤¬
ÀßÄꤵ¤ì¡¢Í׵ᤵ¤ì¤¿¥Ð¥¤¥ÈÎó¤Ë 0 ¤¬½ÐÎϤµ¤ì¤Þ¤¹¡£
¤³¤ì¤Ï¥Ç¥Ð¥Ã¥°ÍѤΥª¥×¥·¥ç¥ó¤Ç¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤ÎÄã²¼¤Ë¶¯¤¤±Æ¶Á¤òÍ¿¤¨¤Þ¤¹¡£
.It <
¥­¥ã¥Ã¥·¥å¥µ¥¤¥º¤ò 2 ʬ¤Î 1 ¤Ë¤·¤Þ¤¹¡£
¥Ç¥Õ¥©¥ë¥È¤Î¥­¥ã¥Ã¥·¥å¥µ¥¤¥º¤Ï 16 ¥Ú¡¼¥¸¤Ç¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤ÏÊ£¿ô²ó»ØÄê¤Ç¤­¤Þ¤¹¡£
.It >
¥­¥ã¥Ã¥·¥å¥µ¥¤¥º¤ò 2 Çܤˤ·¤Þ¤¹¡£
¥Ç¥Õ¥©¥ë¥È¤Î¥­¥ã¥Ã¥·¥å¥µ¥¤¥º¤Ï 16 ¥Ú¡¼¥¸¤Ç¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤ÏÊ£¿ô²ó»ØÄê¤Ç¤­¤Þ¤¹¡£
.El
.Pp
.Dq J
¥ª¥×¥·¥ç¥ó¤È
.Dq Z
¥ª¥×¥·¥ç¥ó¤Ï¡¢¥Æ¥¹¥È¤È¥Ç¥Ð¥Ã¥°ÍѤǤ¹¡£
¤³¤ì¤é¤Î¥ª¥×¥·¥ç¥ó¤ò»ÈÍѤ·¤Æ¤¤¤ë¤È¤­¤Ë
Æ°ºî¤¬ÊѤï¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ë¤Ï·ç´Ù¤¬¤¢¤ê¤Þ¤¹¡£
.Sh »ÈÍÑÎã
¥­¥ã¥Ã¥·¥å¥µ¥¤¥º¤ò¥·¥¹¥Æ¥àÁ´ÂΤǾ®¤µ¤¯¤·¡¢
ÌäÂ꤬ȯÀ¸¤·¤¿¾ì¹ç¤Ï¾ï¤Ë¥³¥¢¥À¥ó¥×¤ò¼è¤ë¤è¤¦¤ÊÀßÄê¤Ï¡¢
.Pp
.Bd -literal -offset indent
ln -s 'A<' /etc/malloc.conf
.Ed
.Pp
¥×¥í¥°¥é¥à¤¬¤³¤ì¤é¤Î´Ø¿ô¤Î¸Æ½Ð¤·»þ¤ËÌá¤êÃͤò¥Á¥§¥Ã¥¯¤·¤Ê¤¤¤³¤È¤ò
¥½¡¼¥¹¤ÇÌÀ¼¨¤¹¤ë¤Ë¤Ï¡¢
.Bd -literal -offset indent
extern char *malloc_options;
malloc_options = "X";
.Ed
.Sh ´Ä¶­ÊÑ¿ô
°Ê²¼¤Î´Ä¶­ÊÑ¿ô¤Ï¡¢¥á¥â¥ê³ä¤êÅö¤Æ´Ø¿ô¤Î¼Â¹Ô¤Ë±Æ¶Á¤òÍ¿¤¨¤Þ¤¹¡£
.Bl -tag -width ".Ev MALLOC_OPTIONS"
.It Ev MALLOC_OPTIONS
´Ä¶­ÊÑ¿ô
.Ev MALLOC_OPTIONS
¤òÀßÄꤹ¤ë¤È¡¢¤³¤Î´Ä¶­ÊÑ¿ô¤Ë´Þ¤Þ¤ì¤ëʸ»ú¤Ï¡¢
¥á¥â¥ê³ä¤êÅö¤Æ´Ø¿ô·²¤Î¥Õ¥é¥°¤È¤·¤Æ²ò¼á¤µ¤ì¤Þ¤¹¡£
.El
.Sh Ìá¤êÃÍ
.Fn malloc
´Ø¿ô¤È
.Fn calloc
´Ø¿ô¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç¤Ï³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤·¡¢
¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï
.Dv NULL
¥Ý¥¤¥ó¥¿¤òÊÖ¤·
.Va errno
¤ò
.Er ENOMEM
¤ËÀßÄꤷ¤Þ¤¹¡£
.Pp
.Fn realloc
´Ø¿ô¤È
.Fn reallocf
´Ø¿ô¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç¤Ï¤â¤·¤«¤·¤¿¤é
.Fa ptr
¤ÈƱ°ì¤Î¡¢³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤·¤Þ¤¹¡£
¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï
.Dv NULL
¥Ý¥¤¥ó¥¿¤òÊÖ¤·¤Þ¤¹¡£
¤½¤Î¾ì¹ç¤Ç¤â
.Fa ptr
¤Ë¤è¤Ã¤Æ»²¾È¤µ¤ì¤ë¥á¥â¥ê¤ÏÍøÍѲÄǽ¤Ç¤½¤Î¤Þ¤Þ»Ä¤ê¤Þ¤¹¡£
¥á¥â¥ê¤Î³ä¤êÅö¤Æ¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤Ï¡¢
.Va errno
¤ò
.Er ENOMEM
¤ËÀßÄꤷ¤Þ¤¹¡£
.Pp
.Fn free
´Ø¿ô¤ÏÃͤòÊÖ¤·¤Þ¤»¤ó¡£
.Pp
.Sh MALLOC ¤ÎÌäÂê¤Î¥Ç¥Ð¥Ã¥°
¤³¤Î¼ÂÁõ¤Ï¡¢
³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤Ê¤¤¸Â¤ê²òÊü¤µ¤ì¤Æ¤¤¤ë¥Ú¡¼¥¸¤Ï¥¢¥¯¥»¥¹¤µ¤ì¤º¡¢
ºÆÍøÍѤΤ¿¤á¤Ë¥«¡¼¥Í¥ë¤ËÀѶËŪ¤ËÊÖ¤µ¤ì¤ë¤È¤¤¤¦ÅÀ¤¬¡¢
¾ (¤Î¥·¥¹¥Æ¥à) ¤Î¥á¥â¥ê³ä¤êÅö¤Æ¤Î¼ÂÁõ¤ÈÂ礭¤¯°Û¤Ê¤ê¤Þ¤¹¡£
.Bd -ragged -offset indent
¤Û¤È¤ó¤É (¤Î¥·¥¹¥Æ¥à) ¤Î¥á¥â¥ê³ä¤êÅö¤Æ¤Î¼ÂÁõ¤Ç¤Ï¡¢
¥ê¥ó¥¯¥É¥ê¥¹¥È¤ò´Þ¤ó¤À¥Ç¡¼¥¿¹½Â¤¤¬¡¢
²òÊü¤µ¤ì¤Æ¤¤¤ë¥á¥â¥ê¤Î¤«¤¿¤Þ¤ê¤ÎÃæ¤ËÊݸ¤µ¤ì¡¢
²òÊü¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¥á¥â¥ê¤ò¸ß¤¤¤Ë·ë¹ç¤¹¤ë¤¿¤á¤Ë»ÈÍѤµ¤ì¤Þ¤¹¡£
²òÊü¥ê¥¹¥È¤ò¹Ô¤­Í褹¤ë¤¿¤Ó¤Ë¡¢
̤»ÈÍѤΡ¢¥Ú¡¼¥¸¥¢¥¦¥È¤µ¤ì¤Æ¤¤¤ë¤Ç¤¢¤í¤¦¥Ú¡¼¥¸¤¬¡¢
¥×¥é¥¤¥Þ¥ê¥á¥â¥ê¤ËÆþ¤ë¤¿¤á¤Ë¥Ú¡¼¥¸¥Õ¥©¥ë¥È¤òµ¯¤³¤¹¤¿¤á¡¢
¤³¤ì¤ÏºÇŬ¤È¤Ï¸À¤¨¤Þ¤»¤ó¡£
¥Ú¡¼¥¸¥ó¥°¤ò¹Ô¤¦¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
1 ¤Ä¤Î¥×¥í¥»¥¹¤Ë¤è¤Ã¤ÆÀ¸¤¸¤ë¥Ú¡¼¥¸¥Õ¥©¥ë¥È¤Î¿ô¤¬
5 ÇܤËÁý²Ã¤¹¤ë·ë²Ì¤È¤Ê¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£
.Ed
.Pp
¤³¤Î¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ë¤Ï¡¢¤³¤ì¤Þ¤Ç¤Ï¸¡½Ð¤µ¤ì¤Ê¤«¤Ã¤¿¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Î
ºÙ¡¹¤È¤·¤¿°ãÈ¿¤¬¡¢¼ÂºÝ¤Ë¸¡½Ð¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤ë¤È¤¤¤¦ÉûºîÍѤ¬¤¢¤ê¤Þ¤¹¡£
¤³¤Î¤¿¤á¡¢¤º¤Ã¤ÈÌäÂê¤Ê¤¯Æ°¤¤¤Æ¤¤¤¿¥×¥í¥°¥é¥à¤¬¡¢¤³¤Î³ä¤êÅö¤Æ¤Î¼ÂÁõ¤È
¥ê¥ó¥¯¤·¤¿¤È¤¿¤ó¤ËÌäÂ꤬³½Ð¤¹¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£
.Pp
ºÇ½é¤Ë¤¹¤ë¤Ù¤­¤³¤È¡¢¤½¤·¤Æ¤â¤Ã¤È¤â½ÅÍפʤ³¤È¤Ï
.Dq A
¥ª¥×¥·¥ç¥ó¤òÀßÄꤹ¤ë¤³¤È¤Ç¤¹¡£
¤³¤Î¥ª¥×¥·¥ç¥ó¤òÀßÄꤹ¤ë¤È¡¢
¤Ç¤­¤ë¤À¤±½èÍý¤ò·Ñ³¤·¤è¤¦¤È¤¹¤ëÄ̾ï¤ÎÊý¿Ë¤ò¤È¤ë¤«¤ï¤ê¤Ë¡¢
ÌäÂ꤬ȯÀ¸¤·¤¿¤È¤­¤Ë (²Äǽ¤Ç¤¢¤ì¤Ð) ¥³¥¢¥À¥ó¥×¤ò¶¯À©Åª¤Ë¼è¤ê¤Þ¤¹¡£
.Pp
¥Ç¥Ð¥Ã¥¬¤Î¥µ¥Ý¡¼¥È¤Î¤¿¤á¤Ë¡¢
ŬÀڤʥª¥×¥·¥ç¥ó¤È¥·¥ó¥Ü¥ë¤Ç¥×¥í¥°¥é¥à¤òºÆ¥³¥ó¥Ñ¥¤¥ë¤¹¤ë¤Î¤¬
¤ª¤½¤é¤¯¸­ÌÀ¤Ç¤¹¡£
.Pp
¥×¥í¥°¥é¥à¤¬¡¢Ä̾ï¤È¤Ï°Û¤Ê¤ë·ë²Ì¤ò½Ð¤·¤¿¤ê¡¢¥³¥¢¥À¥ó¥×¤·¤¿¤ê¡¢
¼¡¤Î¥»¥¯¥·¥ç¥ó¤Çµó¤²¤ë¤è¤¦¤Ê¥á¥Ã¥»¡¼¥¸¤ò½Ð¤µ¤º¤Ë
°ã¤Ã¤¿Æ°ºî¤ò¤·»Ï¤á¤ë¤è¤¦¤Ê¾ì¹ç¤Ï¡¢
¥×¥í¥°¥é¥à¤¬ 0 ¤Î¥Ð¥¤¥È¤ÇËþ¤¿¤µ¤ì¤Æ¤¤¤ëµ­²±Îΰè¤Ë°Í¸¤·¤Æ¤¤¤ë¾ì¹ç¤À¤È
»×¤ï¤ì¤Þ¤¹¡£
.Dq Z
¥ª¥×¥·¥ç¥ó¤òÀßÄꤷ¤Æ¼Â¹Ô¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¾õ¶·¤¬¹¥Å¾¤·¤¿¾ì¹ç¤Ï¡¢¤³¤Î¿ÇÃǤ¬Àµ¤·¤«¤Ã¤¿¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
¤³¤ì¤Ç¤â¥×¥í¥°¥é¥à¤¬¤ª¤«¤·¤ÊÆ°ºî¤ò¤¹¤ë¤è¤¦¤Ê¤é¡¢
³ä¤êÅö¤Æ¤é¤ì¤¿Îΰè°Ê³°¤Î¥á¥â¥ê¡¢
ÂçÄñ¤Ï³ä¤êÅö¤Æ¤é¤ì¤¿Îΰè¤ÎÁ°Êý¤Ç¤Ï¤Ê¤¯¸åÊý¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤È¤¤¤¦ÌäÂê¤À¤È
»×¤ï¤ì¤Þ¤¹¡£
.Pp
¤¢¤ë¤¤¤Ï¡¢¾É¾õ¤¬Íưפ˺Ƹ½¤·¤Ê¤¤¾ì¹ç¤Ï¡¢
.Dq J
¥ª¥×¥·¥ç¥ó¤òÀßÄꤹ¤ë¤ÈÌäÂê¤òµ¯¤³¤¹½õ¤±¤Ë¤Ê¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£
.Pp
ËÜÅö¤ËÆñ¤·¤¤¾õ¶·¤Ç¤Ï¡¢¥«¡¼¥Í¥ë¤Ç
.Dq U
¥ª¥×¥·¥ç¥ó¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¤½¤ì¤òÀßÄꤹ¤ë¤È¡¢
¤³¤ì¤é¤Î´Ø¿ô¤Î¤¹¤Ù¤Æ¤Î¸Æ½Ð¤·¤Î¾ÜºÙ¤Ê¥È¥ì¡¼¥¹¤¬ºîÀ®¤µ¤ì¤Þ¤¹¡£
.Pp
¤¢¤¤¤Ë¤¯¡¢¤³¤Î¼ÂÁõ¤Ç¤Ï¡¢¸¡½Ð¤µ¤ì¤¿ÌäÂê¤Ë´Ø¤¹¤ë¾ÜºÙ¤ÏÄ󶡤µ¤ì¤Þ¤»¤ó¡£
¤½¤Î¤è¤¦¤Ê¾ðÊó¤òÊݸ¤¹¤ë¤³¤È¤Ç¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤¬°­±Æ¶Á¤ò¼õ¤±¤ë¤¿¤á¤Ç¤¹¡£
¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤È°ú¤­´¹¤¨¤Ë¤¤¤Ã¤½¤¦¤Î·òÁ´¤µ¤Î¥Á¥§¥Ã¥¯¤È¾ÜºÙ¤Ê¿ÇÃǤò¹Ô¤¤¡¢
ÌäÂê¤Î¸¡½Ð¤È°ÌÃÖ¤ÎÆÃÄê¤Ë¾ÇÅÀ¤òÅö¤Æ¤¿¿ô¿¤¯¤Î¥á¥â¥ê³ä¤êÅö¤Æ¤Î¼ÂÁõ¤¬¡¢
¥¤¥ó¥¿¡¼¥Í¥Ã¥È¤ÇÍøÍѲÄǽ¤Ç¤¹¡£
.Sh ¿ÇÃÇ¥á¥Ã¥»¡¼¥¸
.Fn malloc ,
.Fn calloc ,
.Fn realloc ,
.Fn free
¤¬¥¨¥é¡¼¤ä·Ù¹ð¤ò¸¡½Ð¤¹¤ë¤È¡¢
¥á¥Ã¥»¡¼¥¸¤¬¥Õ¥¡¥¤¥ëµ­½Ò»Ò STDERR_FILENO ¤Ë½ÐÎϤµ¤ì¤Þ¤¹¡£
¥¨¥é¡¼¤Î¾ì¹ç¡¢¥×¥í¥»¥¹¤Ï¥³¥¢¥À¥ó¥×¤·¤Þ¤¹¡£
.Dq A
¥ª¥×¥·¥ç¥ó¤òÀßÄꤹ¤ë¤È¡¢¤¹¤Ù¤Æ¤Î
·Ù¹ð¤Ï¥¨¥é¡¼¤È¤·¤Æ°·¤ï¤ì¤Þ¤¹¡£
.Pp
°Ê²¼¤Ç¤Ï¡¢½ÐÎϤµ¤ì¤ë²ÄǽÀ­¤¬¤¢¤ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤È¤½¤Î°ÕÌ£¤Ë¤Ä¤¤¤Æ
´Êñ¤ËÀâÌÀ¤·¤Þ¤¹¡£
.Bl -diag
.It "(ES): mumble mumble mumble"
.Dq EXTRA_SANITY
¤¬ÄêµÁ¤µ¤ì¤¿¾õÂ֤ǥá¥â¥ê³ä¤êÅö¤Æ´Ø¿ô¤¬¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤Æ¤ª¤ê¡¢
¾ÜºÙ¤Ê¥¨¥é¡¼¥Á¥§¥Ã¥¯Ãæ¤Ë¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤Þ¤·¤¿¡£
¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢¥½¡¼¥¹¥³¡¼¥É¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
.It "mmap(2) failed, check limits"
¥·¥¹¥Æ¥à¤¬´í¸±¤Ê²áÉé²Ù¤Ê¾õÂ֤Ǥ¢¤ë¤«¡¢¥×¥í¥»¥¹¤ÎÀ©¸Â¤¬Àµ¤·¤¯
»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¤È»×¤ï¤ì¤Þ¤¹¡£
.It "freelist is destroyed"
ÆâÉô¤Î²òÊü¥ê¥¹¥È¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡£
.It "out of memory"
.Dq X
¥ª¥×¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢¤«¤Ä¡¢¥á¥â¥ê¤Î³ä¤êÅö¤Æ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£
.El
.Pp
°Ê²¼¤Ç¤Ï¡¢½ÐÎϤµ¤ì¤ë²ÄǽÀ­¤¬¤¢¤ë·Ù¹ð¥á¥Ã¥»¡¼¥¸¤È¤½¤Î°ÕÌ£¤Ë¤Ä¤¤¤Æ
´Êñ¤ËÀâÌÀ¤·¤Þ¤¹¡£
.Bl -diag
.It "chunk/page is already free"
¤¹¤Ç¤Ë²òÊü¤µ¤ì¤Æ¤¤¤ë¥á¥â¥ê¤ò
.Fn free
¤Ç²òÊü¤·¤è¤¦¤È¤·¤Þ¤·¤¿¡£
.It "junk pointer, ..."
¥á¥â¥ê³ä¤êÅö¤Æ´Ø¿ô¤ËÍ¿¤¨¤é¤ì¤¿¥Ý¥¤¥ó¥¿¤¬¡¢
ǧ¼±¤µ¤ì¤Æ¤¤¤ë¥á¥â¥ê¶­³¦¤Î³°Â¦¤ò»Ø¤·¤Æ¤¤¤Þ¤¹¡£
.It "malloc() has never been called"
¥á¥â¥ê¤¬³ä¤ê¿¶¤é¤ì¤Æ¤¤¤Ê¤¤¤Ë¤â´Ø¤ï¤é¤º¡¢²òÊü¤·¤è¤¦¤È¤·¤¿¤ê¡¢
ºÆ³ä¤êÅö¤Æ¤·¤è¤¦¤È¤·¤Þ¤·¤¿¡£
.It "modified (chunk-/page-) pointer"
.Fn free
¤«
.Fn realloc
¤ËÅϤµ¤ì¤¿¥Ý¥¤¥ó¥¿¤¬½ñ¤­´¹¤¨¤é¤ì¤Æ¤¤¤Þ¤¹¡£
.It "pointer to wrong page"
.Fn realloc ,
.Fn free
¤â¤·¤¯¤Ï
.Fn reallocf
¤¬²òÊü¤·¤è¤¦¤È¤·¤Æ¤¤¤ë¥Ý¥¤¥ó¥¿¤¬¡¢
Àµ¤·¤¤¥Ú¡¼¥¸¤ò»²¾È¤·¤Æ¤¤¤Þ¤»¤ó¡£
.It "recursive call"
¥á¥â¥ê³ä¤êÅö¤Æ´Ø¿ô¤òºÆµ¢Åª¤Ë¸Æ¤Ó½Ð¤½¤¦¤È¤·¤Þ¤·¤¿¡£
¤³¤ì¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£
Æä˥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ç¤Ï¡¢¥á¥â¥ê¤Î³ä¤êÅö¤Æ¤ò¤¹¤ë¤Ù¤­¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
.It "unknown char in MALLOC_OPTIONS"
ÉÔÌÀ¤Ê¥ª¥×¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤Þ¤·¤¿¡£
.Dq A
¥ª¥×¥·¥ç¥ó¤òÀßÄꤷ¤Æ¤¤¤Æ¤â¡¢¤³¤Î·Ù¹ð¤Ïñ¤Ê¤ë·Ù¹ð¤È¤·¤Æ°·¤ï¤ì¤Þ¤¹¡£
.El
.Sh ´ØÏ¢¹àÌÜ
.Xr brk 2 ,
.Xr mmap 2 ,
.Xr alloca 3 ,
.Xr getpagesize 3 ,
.Xr memory 3
.Pa /usr/share/doc/papers/malloc.ascii.gz
.Sh µ¬³Ê
.Fn malloc ,
.Fn calloc ,
.Fn realloc ,
.Fn free
´Ø¿ô¤Ï
.St -isoC
¤ËŬ¹ç¤·¤Æ¤¤¤Þ¤¹¡£
.Sh Îò»Ë
¸½ºß¤Î¥á¥â¥ê³ä¤êÅö¤Æ¤Î¼ÂÁõ¤Ï¡¢
¸ÄÊ̤Υ²¥ë¥Þ¥Ë¥¦¥à¥È¥é¥ó¥¸¥¹¥¿¤ÇºîÀ®¤µ¤ì¤¿¡¢
20 ¥Ó¥Ã¥È¥Ð¥¤¥Ê¥ê¥³¥ó¥Ô¥å¡¼¥¿¤Ë¼è¤êÉÕ¤±¤é¤ì¤¿¥É¥é¥à¤Î
¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤È¤·¤Æ¥¹¥¿¡¼¥È¤·¤Þ¤·¤¿¡£
¤½¤ì°Ê¹ß¤Ï¡¢Æó¼¡Êݸ°è¤Ç¤Ï¤Ê¤¯¡¢°ì¼¡Êݸ°è¤òÁàºî¤¹¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤·¤¿¡£
¤³¤Î¿·¤·¤¤·ÁÂ֤ȵ¡Ç½¤Ï
.Fx 2.2
¤Ç¤Ï¤¸¤á¤ÆÅо줷¤Þ¤·¤¿¡£
.Pp
.Xr reallocf 3
´Ø¿ô¤Ï
.Fx 3.0
¤Ç¤Ï¤¸¤á¤ÆÅо줷¤Þ¤·¤¿¡£
.Sh ºî¼Ô
.An Poul-Henning Kamp Aq phk@FreeBSD.org
.Sh ¥Ð¥°
ÌäÂ꤬ȯÀ¸¤·¤¿¾ì¹ç¤Ë½ÐÎϤµ¤ì¤ë¥á¥Ã¥»¡¼¥¸¤Ï¡¢
¼ÂºÝ¤ÎÃͤˤĤ¤¤Æ¤Î¾ÜºÙ¤òÄ󶡤·¤Þ¤»¤ó¡£
.Pp
0 ¥Ð¥¤¥È¤ò³ä¤êÅö¤Æ¤ë¤è¤¦¤ËÍ׵ᤵ¤ì¤¿¾ì¹ç¤Ë
.Dv NULL
¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¤³¤È¤Ï¡¢¶ò¤«¤ÊÌ䤤¤«¤±¤ËÂФ¹¤ë¶ò¤«¤ÊÈ¿±þ¤Ç¤¢¤ë¤È¸À¤¨¤Þ¤¹¡£