CopyOnWriteArrayList原始碼分析

2021-09-19 04:57:29 字數 446 閱讀 2889

copyonwtitearraylist的讀操作效能優越,但是基於copyonwtitearraylist的寫操作效能卻不盡人意。以下是copyonwritearraylist的add()方法實現。

public e set(int index, e element)  else 

return oldvalue;

} finally

}

寫操作,比如向容器中天劍乙個元素,則首先將當前容器複製乙份,然後在新副本上執行寫操作,結束之後再將原容器的引用指向新容器。

缺點:記憶體占用高,每次讀操作都要將元容器拷貝乙份,數量大時,對記憶體壓力較大,可能會引起頻繁gc

注意:在讀多寫少的高併發環境中,使用copyonwritearraylist可以提高系統的效能。但是在寫多讀少的場合,copyonwritearraylist的效能可能不如vector

Cartographer原始碼篇 原始碼分析 1

在安裝編譯cartographer 1.0.0的時候,我們可以看到 主要包括cartorgarpher ros cartographer ceres sover三個部分。其中,ceres solver用於非線性優化,求解最小二乘問題 cartographer ros為ros平台的封裝,獲取感測器資料...

AbstractListView原始碼分析3

normal list that does not indicate choices public static final int choice mode none 0 the list allows up to one choice public static final int choice ...

Android AsyncTask原始碼分析

android中只能在主線程中進行ui操作,如果是其它子執行緒,需要借助非同步訊息處理機制handler。除此之外,還有個非常方便的asynctask類,這個類內部封裝了handler和執行緒池。本文先簡要介紹asynctask的用法,然後分析具體實現。asynctask是乙個抽象類,我們需要建立子...