Thursday, 27 December 2018

Empty Swift string Memory allocation Layout (Stack/ Heap allocation)

In swift, strings are struct types, so the values are going to be stored in stack memory rather than the heap.

Lets say we declare a string:

let a = ""
let b = "o"

This is an empty string, but some memory is allocated. I need to know what is the difference in the memory given to an empty string and a string with let's say count 1.


If we say:-

var str:String?
var str: String = ""

The difference in memory layout by drawing is what I need to see. (stack / heap).

I tried to find this on google but nowhere I can't find the memory layout for this.



from Empty Swift string Memory allocation Layout (Stack/ Heap allocation)

No comments:

Post a Comment