Advanced Swift: Unsafe Memory Access · Conclusion |

This is a companion discussion topic for the original entry at

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: How to get available memory C++/g++? - Stack Overflow