How do I limit C program memory allocation to 1 virtual page on macOS Sonoma?

Hello I was wondering if there is a way to ensure that a C program I am writing can only write to 1 virtual page. I am trying to test how space efficient different Mallocs are and I need a way to ensure that the OS will not try to swap out pages making the space efficiency test pointless. I am on Mac OS Sonoma v14.5




[Re-Titled by Moderator]

Posted on Mar 6, 2025 09:24 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 6, 2025 09:47 PM

It is generally a bad idea to attempt out-smarting memory management, as it often backfires, either on your program or affecting other programs running on the system.


Look at mmap(2) and mlock(2)

1 reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I limit C program memory allocation to 1 virtual page on macOS Sonoma?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.