📄 realloc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>realloc</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="realloc"></a> <a name="tag_03_598"></a><!-- realloc --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_598_01"></a>NAME</h4><blockquote>realloc - memory reallocator</blockquote><h4><a name="tag_03_598_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/stdlib.h.html">stdlib.h</a>><br><br> void *realloc(void *</tt><i>ptr</i><tt>, size_t</tt> <i>size</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_598_03"></a>DESCRIPTION</h4><blockquote><div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"border="0"> The functionality described on this reference page is aligned with the ISO C standard. Any conflict between therequirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers tothe ISO C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div><p>The <i>realloc</i>() function shall change the size of the memory object pointed to by <i>ptr</i> to the size specified by<i>size</i>. The contents of the object shall remain unchanged up to the lesser of the new and old sizes. If the new size of thememory object would require movement of the object, the space for the previous instantiation of the object is freed. If the newsize is larger, the contents of the newly allocated portion of the object are unspecified. If <i>size</i> is 0 and <i>ptr</i> isnot a null pointer, the object pointed to is freed. If the space cannot be allocated, the object shall remain unchanged.</p><p>If <i>ptr</i> is a null pointer, <i>realloc</i>() shall be equivalent to <a href="../functions/malloc.html"><i>malloc</i>()</a>for the specified size.</p><p>If <i>ptr</i> does not match a pointer returned earlier by <a href="../functions/calloc.html"><i>calloc</i>()</a>, <a href="../functions/malloc.html"><i>malloc</i>()</a>, or <i>realloc</i>() or if the space has previously been deallocated by a call to <ahref="../functions/free.html"><i>free</i>()</a> or <i>realloc</i>(), the behavior is undefined.</p><p>The order and contiguity of storage allocated by successive calls to <i>realloc</i>() is unspecified. The pointer returned ifthe allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used toaccess such an object in the space allocated (until the space is explicitly freed or reallocated). Each such allocation shall yielda pointer to an object disjoint from any other object. The pointer returned shall point to the start (lowest byte address) of theallocated space. If the space cannot be allocated, a null pointer shall be returned.</p></blockquote><h4><a name="tag_03_598_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion with a size not equal to 0, <i>realloc</i>() shall return a pointer to the (possibly moved) allocatedspace. If <i>size</i> is 0, either a null pointer or a unique pointer that can be successfully passed to <a href="../functions/free.html"><i>free</i>()</a> shall be returned. If there is not enough available memory, <i>realloc</i>() shallreturn a null pointer <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and set <i>errno</i> to [ENOMEM]. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><h4><a name="tag_03_598_05"></a>ERRORS</h4><blockquote><p>The <i>realloc</i>() function shall fail if:</p><dl compact><dt>[ENOMEM]</dt><dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Insufficient memory is available. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_598_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_598_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_598_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_598_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_598_10"></a>SEE ALSO</h4><blockquote><p><a href="calloc.html"><i>calloc</i>()</a> , <a href="free.html"><i>free</i>()</a> , <a href="malloc.html"><i>malloc</i>()</a> ,the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/stdlib.h.html"><i><stdlib.h></i></a></p></blockquote><h4><a name="tag_03_598_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 1. Derived from Issue 1 of the SVID.</p></blockquote><h4><a name="tag_03_598_12"></a>Issue 6</h4><blockquote><p>Extensions beyond the ISO C standard are marked.</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>In the RETURN VALUE section, if there is not enough available memory, the setting of <i>errno</i> to [ENOMEM] is added.</p></li><li><p>The [ENOMEM] error condition is added.</p></li></ul></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -