Value Types and Reference Types

2022-11-09  本文已影响0人  踏云小子

Contents

A brief introduction

image.png

An example

Why did they have this difference

Allocation

Method dispatch

Static dispatch
Dynamic dispatch
Increasing Performance by Reducing Dynamic Dispatch

我们知道Static dispatch快于Dynamic dispatch,如何在开发中去尽可能使用Static dispatch

When to use Value Types

This is especially helpful in multi-threaded environments where a different thread could alter your data.
Use a value type when you want copies to have an independent state, and the data will be used in code across multiple threads.

In Swift, Array, String, and Dictionary are all value types.

Mixed Types

Q&A

refer

上一篇 下一篇

猜你喜欢

热点阅读