tezvyn:

Struct versus class performance and memory tradeoffs

Source: interviewintermediate

WHAT IT TESTS: value versus reference semantics and allocation cost. OUTLINE: structs are value types, often stack-allocated with no ARC; classes are heap-allocated reference types with retain counts. RED FLAG: claiming structs are always faster.

WHAT IT TESTS: understanding of value versus reference semantics and where allocation happens. ANSWER OUTLINE: structs are value types with copy semantics, frequently stored inline or on the stack and free of ARC traffic, which makes small immutable data cheap; classes are reference types living on the heap, requiring allocation and atomic retain or release on every assignment.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Struct versus class performance and memory tradeoffs · Tezvyn