Advanced Swift: Unsafe Memory Access · Conclusion | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1940773-advanced-swift-unsafe-memory-access/lessons/6

Hi Ray,
That’s a great course. One thing I still miss how to check the size of the available memory before allocating. Typical use case when you want to check the theoretical size of an array for a particular calculation.

Thanks for the question. I don’t know either! Actually checking memory size is a system level concern so there are no Swift standard library APIs for it. If you are on a system with virtual memory (non-iOS) you can allocate huge arrays and they will succeed even if you exceed physical memory!

You could call a C api but it depends what system you are running on. Check out this stack overflow: https://stackoverflow.com/questions/2513505/how-to-get-available-memory-c-g