To answer the OP’s original question, I’m not sure about the exact rules Apple 
is using on iOS, but I’d expect the memory limit to apply to *private* memory, 
namely that allocated using malloc() et al, plus dirty pages mapped with 
mmap()’s MAP_PRIVATE flag.  Read-only and shared mappings that are backed by a 
file or by swap wouldn’t count; nor would non-dirty pages mapped with 
MAP_PRIVATE, because in all of those cases the data can be purged from RAM and 
retrieved from storage (disk or Flash) when needed.

On 4 May 2017, at 07:27, Doug Hill <cocoa...@breaqz.com> wrote:
> 
> The limits of mmap should be the limits of the file system. Well, technically 
> it’s limited by the size_t parameter which I guess is OS specific. But these 
> days it should be what the VFS can handle.

It’s limited by:

- The length of files allowed by the filesystem
- Available, suitably aligned, contiguous address space in the virtual memory 
map
- Available space in the page table (usually this shouldn’t be an issue on 
normal operating systems)

size_t is generally specified to be the same width as a pointer on the target 
architecture - otherwise it would unnecessarily restrict all kinds of things.  
Strictly speaking, the C standard only requires that size_t be at least 16 bits 
in size (and says it’s the type of the result of the sizeof operator), but in 
practice on a 32-bit machine it’ll be 32-bit, and on a 64-bit machine it’ll be 
64-bit.  AFAIK the only time things might get complicated is if you were 
dealing with hairy old segmented x86 code, which you aren’t.

Note that the filesystem may well allow files larger than the address space, 
particularly on 32-bit systems.  That isn’t necessarily a problem - you cannot, 
after all, mmap() more of the file than you have address space, and if you are 
particularly set on using mmap() even in that case you can use the “offset” 
argument to choose which part of the data you’re mapping in.

On a 64-bit system, mmap() is a reasonable thing to do even for large files.  
On a 32-bit system, I’d steer clear of using mmap() for anything large; it 
still has its uses, but you can run out of address space too easily.

Kind regards,

Alastair.

--
http://alastairs-place.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to