Reputation: 42642
In Swift, String
and Array
are implemented as struct
And, struct
is being created in stack memory.
And, stack memory has very limited size (Is the stack size of iPhone fixed?), compared to heap memory.
Does that also mean?
String
is limited by stack memory size?Array
, is limited by stack memory size?Upvotes: 0
Views: 99
Reputation: 63137
Array
, String
and every other dynamically sized-collection (ArraySlice
, Substring
, Set
, Dictionary
, etc.) are implemented as structs that contain a reference to a heap-allocated buffer.
Almost everything that Array
does is functionality that already exists on its internal buffer. But the Array
struct is responsible for implementing the copy-on-write functionality that's so pervasively relied-upon in the Swift world.
Upvotes: 4