CoolBrain CoolBrain - 6 months ago 10
Swift Question

Operations that use only RAM

Can you please tell me some example code where we use ignorable amount of CPU and storage but heavy use of RAM? Like, if I run a loop and create objects, this will consume RAM but not CPU or storage. I mean tell me some memory expensive operations.

Answer

In Swift the Int64 type requires 64 bit of memory. So if you allocate space for 1000000 Int64 you will reserve memory for 8 MB.

UnsafeMutablePointer<Int64>.alloc(1000000)

The process should not consume much CPU since you are not initializing that memory, you are just allocating it.

Comments