4 <strong>Function
</strong> - Allocate a region of virtual memory.
7 <strong>kern_return_t vm_allocate
</strong>
8 <strong>(vm_task_t
</strong> <var>target_task
</var>,
9 <strong>vm_address_t
</strong> <var>address
</var>,
10 <strong>vm_size_t
</strong> <var>size
</var>,
11 <strong>boolean_t
</strong> <var>anywhere
</var><strong>);
</strong>
16 <dt> <var>target_task
</var>
19 The port for the task in whose address space the
20 region is to be allocated.
22 <dt> <var>address
</var>
24 [pointer to in/out scalar]
25 The starting address for the region. If the
26 region as specified by the given starting address and size would not lie
27 within the task's un-allocated memory, the kernel does not allocate the
28 region. If allocated, the kernel returns the starting address actually used
29 for the allocated region.
34 The number of bytes to allocate.
36 <dt> <var>anywhere
</var>
39 Placement indicator. The valid values are:
42 <dt> <strong>TRUE
</strong>
44 The kernel allocates the region in the next unused space that
45 is sufficient within the address space. The kernel returns the
46 starting address actually used in
<var>address
</var>.
48 <dt> <strong>FALSE
</strong>
50 The kernel allocates the region starting at
<var>address
</var> unless that
51 space is already allocated.
56 The
<strong>vm_allocate
</strong> function allocates a region of virtual
57 memory in the specified
58 task's address space. A new region is always zero filled.
60 If
<var>anywhere
</var> is
<strong>TRUE
</strong>, the returned
61 <var>address
</var> will be at
62 a page boundary; otherwise, the region starts at the beginning
64 containing
<var>address
</var>.
65 <var>size
</var> is always rounded up to an integral number of pages.
66 Because of this rounding to virtual page boundaries, the amount of memory
67 allocated may be greater than
<var>size
</var>. Use
<strong>host_page_size
</strong> to find
68 the current virtual page size.
70 Initially, there are no access restrictions on any of the pages of the newly
71 allocated region. Child tasks inherit the new region as a copy.
74 To establish different protections or inheritance for the new region, use the
75 <strong>vm_protect
</strong> and
<strong>vm_inherit
</strong> functions.
77 A task's address space can contain both explicitly allocated memory and
78 automatically allocated memory. The
<strong>vm_allocate
</strong> function
80 memory. The kernel automatically allocates memory to hold out-of-line data
81 passed in a message (and received with
<strong>mach_msg
</strong>). The kernel allocates
82 memory for the passed data as an integral number of pages.
84 This interface is machine word length dependent because of the virtual address
86 <h3>RETURN VALUES
</h3>
89 <dt> <strong>KERN_INVALID_ADDRESS
</strong>
91 The specified address is illegal or reserved.
93 <dt> <strong>KERN_NO_SPACE
</strong>
95 There is not enough space in the task's address space to allocate the
98 <h3>RELATED INFORMATION
</h3>
101 <a href=
"vm_deallocate.html"><strong>vm_deallocate
</strong></a>,
102 <a href=
"vm_inherit.html"><strong>vm_inherit
</strong></a>,
103 <a href=
"vm_protect.html"><strong>vm_protect
</strong></a>,
104 <a href=
"vm_region.html"><strong>vm_region
</strong></a>,
105 <a href=
"host_page_size.html"><strong>host_page_size
</strong></a>.