Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Standard <code>malloc</code> is defined in the C standard to allocate a contiguous block of memory (at least it appears so to you) - it will return a null pointer if the allocation fails.</p> <p>At a lower level, the OS will be doing something like what <a href="https://stackoverflow.com/questions/3954188/how-malloc-works/3954215#3954215">kotlinski</a> or <a href="https://stackoverflow.com/questions/3954188/how-malloc-works/3954221#3954221">Blank Xavier</a> have described in their respective answers.</p> <p>From <strong>§7.20.3</strong> of the <strong>ISO/IEC 9899-1999 C Standard</strong>:</p> <blockquote> <p>The pointer returned if the allocation (by <code>calloc</code>, <code>realloc</code>, or <code>malloc</code>) succeeds is suitably aligned so that it may be assigned to a pointer to any type of object and then <strong>used to access such an object or an array of such objects in the space allocated</strong> (until the space is explicitly deallocated).</p> </blockquote> <p>It is not that explicit, but the paragraph mentions 'accessing an array of such objects', and in the C standard, arrays are:</p> <blockquote> <p>An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. (from <strong>§6.2.5</strong>)</p> </blockquote> <p>Also note that subsequent calls to <code>calloc</code>, <code>realloc</code>, and <code>malloc</code> do not guarantee contiguity or ordering of memory (with other memory blocks already allocated).</p> <p>This point is also specified in <strong>§7.20.3</strong>.</p> <blockquote> <p>The order and contiguity of storage allocated by successive calls to the <code>calloc</code>, <code>malloc</code>, and <code>realloc</code> functions is unspecified.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload