颤振稳定性叶瓣图
Ever wondered how flutter handles all your UI building and events like Futures, taps, etc.. on a single thread( yes it does all that on a single thread 😮😮😮 until and unless explicitly done).
曾经想知道flutter如何在单个线程上处理所有UI构建和事件,例如Future,taps等。(是的,它在单个线程上完成所有操作😮😮😮直到并且除非明确完成)。
什么是线程/隔离? (What is Thread/Isolates ?)
Thread is an independent process that has its own chunk of memory and executes the given instructions on that memory , It can work parallelly with other threads hence can reduce execution time of multiple process on a single thread .
线程是一个独立的进程,具有自己的内存块并在该内存上执行给定的指令。它可以与其他线程并行工作,因此可以减少单个线程上多个进程的执行时间。
Let’s understand this with an example :
让我们通过一个例子来理解这一点:
In Fps games like counter strike, Call of duty, etc. you can see that as soon as you fire a weapon few tasks executes simultaneously like playing of bullet sound, change of bullet count and reduction in opponent health , All these things happens parallelly these are basically threads which execute parallelly and execute their task on separate isolates(isolates and threads can be used interchangeably as isolate is a Dart way of multi threading more on that below) which have its own memory.
在Fps游戏中,例如反恐精英,使命召唤等,您可以看到,一旦发射武器,几乎没有同时执行的任务,例如弹奏子弹声,改变子弹数和减少对手的生命值,所有这些并行发生基本上是并行执行并在单独的隔离上执行其任务的线程(隔离和线程可以互换使用,因为隔离是Dart在下面的更多内容中介绍的多线程方法),它具有自己的内存。
Languages like JAVA and C++ Share Their heap memory with threads, but in case of flutter, every isolate has its own memory and works independently. As it has its own private space this memory doesn’t require locking, as if a thread finishes its task it already means that the thread has finished utilizing its memory space and then that memory can go for garbage collection.
诸如JAVA和C ++之类的语言与线程共享它们的堆内存,但是在出现混乱的情况下,每个隔离都有自己的内存并且可以独立工作。 由于该内存具有自己的私有空间,因此不需要锁定,就好像一个线程完成了它的任务一样,这意味着该线程已经完成了对它的内存空间的利用,然后该内存可以用于垃圾回收了。