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鈥檚 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鈥檛 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