thanks Steve it’s quite useful
but again, if you take a look at documentation of the vm_allocate, you’ll see
(https://opensource.apple.com/source/xnu/xnu-792.6.56/osfmk/man/vm_allocate.html?txt
<https://opensource.apple.com/source/xnu/xnu-792.6.56/osfmk/man/vm_allocate.html?txt>)
Function - Allocate a region of virtual memory.
SYNOPSIS
kern_return_t vm_allocate
(vm_task_t target_task,
vm_address_t address,
vm_size_t size,
boolean_t anywhere);
. . . . . . . . .
RETURN VALUES
KERN_INVALID_ADDRESS
The specified address is illegal or reserved.
KERN_NO_SPACE
There is not enough space in the task's address space to allocate the new
region.
so as you can see vm_allocate might fail and in that case it will return error
code
also as I pointed out earlier, debug build doesn’t have any problem with
identification of the malloc failure
thanks again
dm
> On Jul 4, 2016, at 8:20 PM, Steve Sisak <[email protected]> wrote:
>
>
>> On Jul 4, 2016, at 8:12 PM, Steve Sisak <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> I think there may be more information in the guidelines, but don’t have time
>> to re-read the full document at the moment.
>>
>
>
> Found it:
>
> https://developer.apple.com/library/prerelease/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MemoryAlloc.html#//apple_ref/doc/uid/20001881-99765
>
> <https://developer.apple.com/library/prerelease/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MemoryAlloc.html#//apple_ref/doc/uid/20001881-99765>
> Allocating Large Memory Blocks using Malloc
> For large memory allocations, where large is anything more than a few virtual
> memory pages, malloc automatically uses the vm_allocateroutine to obtain the
> requested memory. The vm_allocate routine assigns an address range to the new
> block in the logical address space of the current process, but it does not
> assign any physical memory to those pages right away. Instead, the kernel
> does the following:
> <>It maps a range of memory in the virtual address space of this process by
> creating a map entry; the map entry is a simple structure that defines the
> starting and ending addresses of the region.
> The range of memory is backed by the default pager.
> The kernel creates and initializes a VM object, associating it with the map
> entry.
> At this point there are no pages resident in physical memory and no pages in
> the backing store. Everything is mapped virtually within the system. When
> your code accesses part of the memory block, by reading or writing to a
> specific address in it, a fault occurs because that address has not been
> mapped to physical memory. In OS X, the kernel also recognizes that the VM
> object has no backing store for the page on which this address occurs. The
> kernel then performs the following steps for each page fault: <>
> It acquires a page from the free list and fills it with zeroes.
> It inserts a reference to this page in the VM object’s list of resident pages.
> <> <>It maps the virtual page to the physical page by filling in a data
> structure called the pmap. The pmap contains the page table used by the
> processor (or by a separate memory management unit) to map a given virtual
> address to the actual hardware address.
> The granularity <> of large memory blocks is equal to the size of a virtual
> memory page, or 4096 bytes. In other words, any large memory allocations that
> are not a multiple of 4096 are rounded up to this multiple automatically.
> Thus, if you are allocating large memory buffers, you should make your buffer
> a multiple of this size to avoid wasting memory.
> <>
Dmitry Markman
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com
This email sent to [email protected]