在ARM處理器的Ubuntu系統上安裝 .NET SDK(Core 3.1~7.0),並檢測ARM內在函數的支持情況

来源:https://www.cnblogs.com/zyl910/archive/2022/11/28/arm_ubuntu_install_dotnet_sdk.html
-Advertisement-
Play Games

public static void GetRegistData() { string name = "huishuangzhu"; //搜索到註冊表根目錄 RegistryKey hkml = Registry.ClassesRoot; //搜索到註冊表根目錄下的XXX文件夾。 RegistryK ...


作者:

目錄
目錄

    在前一篇文章(在亞馬遜AWS上創建ARM伺服器並配置好RDP遠程桌面連接的心得)里,我們成功在亞馬遜AWS上創建了Ubuntu系統的ARM伺服器。現在準備在該伺服器上安裝 .NET SDK。

    一、嘗試 apt-get 安裝

    首先嘗試了之前在 x86 處理器的Ubuntu系統上安裝 .NET SDK的經驗,使用 apt-get 來安裝。

    ubuntu@ip-175-76-22-54:~$ sudo apt-get install -y dotnet6
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    E: Unable to locate package dotnet6
    

    遇到錯誤,找不到“dotnet6”的安裝包。隨後換了幾個版本也不行,sudo apt-get update 也沒效果。

    於是查找了一下官方文檔,發現 《在 Ubuntu 上安裝 .NET SDK 或 .NET 運行時》中有這一段話:

    僅在 x64 體繫結構上支持包管理器安裝。 對於 Arm 等其他體繫結構,必須通過其他一些方式安裝 .NET,例如,通過 Snap 和安裝程式腳本進行安裝,或通過手動提取二進位文件進行安裝。
    

    原來ARM體系不支持包管理安裝,看來得換一種辦法來安裝了。

    二、嘗試 snap 安裝

    現在來嘗試 snap 安裝。
    摘錄官方文檔:

    若要安裝適用於 .NET SDK 的 Snap 包,請運行 snap install 命令。 使用 --channel 參數來指明要安裝哪個版本。 如果省略此參數,則使用 latest/stable。 在下麵的示例中,指定的是 7.0:
    
    Bash
    sudo snap install dotnet-sdk --classic --channel=7.0
    

    隨後參考它,在我們的ARM伺服器上執行命令。

    ubuntu@ip-175-76-22-54:~$ sudo snap install dotnet-sdk --classic --channel=7.0
    error: snap "dotnet-sdk" is not available on 7.0/stable but other tracks exist.
    
           Please be mindful that different tracks may include different features.
           Get more information with 'snap info dotnet-sdk'.
    

    有報錯,說找不到可用的安裝包。
    於是用命令查詢了一下 snap 上有哪些 dotnet-sdk 版本。

    ubuntu@ip-175-76-22-54:~$ snap info dotnet-sdk
    name:      dotnet-sdk
    summary:   Develop high performance applications in less time, on any platform.
    publisher: Microsoft .NET Core (dotnetcore✓)
    store-url: https://snapcraft.io/dotnet-sdk
    contact:   https://dot.net/core
    license:   MIT
    description: |
      .NET Core is the modular and high performance implementation of .NET for
      creating web applications and services that run on Windows, Linux and Mac.
      It is open source and it can share the same code with .NET Framework and
      Xamarin apps.
    
      .NET Core is a .NET Foundation project. https://dotnetfoundation.org/
    snap-id: uHc4y9lWxyqYfxsqcr4xILzAai4L1BHs
    channels:
      5.0/stable:    –
      5.0/candidate: –
      5.0/beta:      –
      5.0/edge:      5.0.100-preview.3.20216.6 2020-04-21 (79) 127MB classic
    

    發現它不支持 .net 7.0,僅有 .net 5.0版的。且沒有穩定版(stable),只在edge通道有一個預覽版(preview)。
    故再換一種辦法吧。

    三、使用 dotnet-install 腳本安裝

    3.1 腳本準備

    摘自官方文檔:

    腳本安裝
    dotnet-install 腳本用於 SDK 和運行時的自動化和非管理員安裝。 可通過 https://dot.net/v1/dotnet-install.sh 下載腳本。
    
    重要:需要 Bash 才能運行該腳本。
    運行此腳本之前,需要授予此腳本作為可執行文件運行的許可權:
    
    Bash
    sudo chmod +x ./dotnet-install.sh
    

    上文介紹了腳本的網址,於是我們可以用 wget 命令下載該腳本,然後參考它修改文件屬性。

    ubuntu@ip-175-76-22-54:~$ wget https://dot.net/v1/dotnet-install.sh
    --2022-11-26 08:28:01--  https://dot.net/v1/dotnet-install.sh
    Resolving dot.net (dot.net)... 20.53.203.50, 20.112.52.29, 20.103.85.33, ...
    Connecting to dot.net (dot.net)|20.53.203.50|:443... connected.
    HTTP request sent, awaiting response... 301 Moved Permanently
    Location: https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh [following]
    --2022-11-26 08:28:02--  https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh
    Resolving dotnet.microsoft.com (dotnet.microsoft.com)... 13.107.246.46, 13.107.213.46, 2620:1ec:46::46, ...
    Connecting to dotnet.microsoft.com (dotnet.microsoft.com)|13.107.246.46|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Cookie coming from dotnet.microsoft.com attempted to set domain to dotnetwebsite.azurewebsites.net
    Cookie coming from dotnet.microsoft.com attempted to set domain to dotnetwebsite.azurewebsites.net
    Length: 58293 (57K) [application/x-sh]
    Saving to: ‘dotnet-install.sh’
    
    dotnet-install.sh   100%[===================>]  56.93K  --.-KB/s    in 0.003s
    
    2022-11-26 08:28:02 (20.4 MB/s) - ‘dotnet-install.sh’ saved [58293/58293]
    
    ubuntu@ip-175-76-22-54:~$ sudo chmod +x ./dotnet-install.sh
    

    3.2 安裝最新長期支持 (LTS)版 .NET 6.0

    對於安裝最新的長期支持 (LTS),可參考官方文檔:

    該腳本預設安裝最新的 長期支持 (LTS) SDK 版本,即 .NET 6。 若要安裝最新版本(可能不是 LTS) 版本的 (版本),請使用 --version latest 參數。
    
    Bash
    ./dotnet-install.sh --version latest
    

    註意它在運行腳本時,沒有加“sudo”,表示該腳本支持將程式安裝到當前用戶的目錄下,無需管理員許可權。
    但這對多用戶使用時會帶來麻煩。為了避免每個用戶都裝一次,於是也可選擇用“sudo”來安裝,這樣便會安裝在所有用戶都能訪問的路徑中。

    ubuntu@ip-175-76-22-54:~$ sudo ./dotnet-install.sh
    dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
    dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
    dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
    dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
    
    dotnet-install: Attempting to download using aka.ms link https://dotnetcli.azureedge.net/dotnet/Sdk/6.0.403/dotnet-sdk-6.0.403-linux-arm64.tar.gz
    dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/6.0.403/dotnet-sdk-6.0.403-linux-arm64.tar.gz
    dotnet-install: Installed version is 6.0.403
    dotnet-install: Adding to current process PATH: `/root/.dotnet`. Note: This change will be visible only when sourcing script.
    dotnet-install: Note that the script does not resolve dependencies during installation.
    dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
    dotnet-install: Installation finished successfully.
    

    從上面的信息可看出,已安裝好 .NET SDK 6.0,它裝在 /root/.dotnet 目錄中。

    3.3 安裝最新版本 .NET 7.0

    對於安裝指定的版本,可參考官方文檔:

    可以使用 參數安裝特定的主版本 --channel ,以指示特定版本。 以下命令安裝 .NET 7.0 SDK。
    
    Bash
    ./dotnet-install.sh --channel 7.0
    

    按照文檔,進行安裝。

    ubuntu@ip-175-76-22-54:~$ sudo ./dotnet-install.sh --channel 7.0
    dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
    dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
    dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
    dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
    
    dotnet-install: Attempting to download using aka.ms link https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.100/dotnet-sdk-7.0.100-linux-arm64.tar.gz
    dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.100/dotnet-sdk-7.0.100-linux-arm64.tar.gz
    dotnet-install: Installed version is 7.0.100
    dotnet-install: Adding to current process PATH: `/root/.dotnet`. Note: This change will be visible only when sourcing script.
    dotnet-install: Note that the script does not resolve dependencies during installation.
    dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
    dotnet-install: Installation finished successfully.
    

    .NET SDK 7.0 安裝成功。

    3.4 安裝舊版本 .NET Core 3.1

    官方文檔的“受支持”列表裡還有“.NET Core 3.1”,於是也可安裝。

    ubuntu@ip-175-76-22-54:~$ sudo ./dotnet-install.sh --channel 3.1
    dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
    dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
    dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
    dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
    
    dotnet-install: Attempting to download using primary link https://dotnetcli.azureedge.net/dotnet/Sdk/3.1.425/dotnet-sdk-3.1.425-linux-arm64.tar.gz
    dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/3.1.425/dotnet-sdk-3.1.425-linux-arm64.tar.gz
    dotnet-install: Installed version is 3.1.425
    dotnet-install: Adding to current process PATH: `/root/.dotnet`. Note: This change will be visible only when sourcing script.
    dotnet-install: Note that the script does not resolve dependencies during installation.
    dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
    dotnet-install: Installation finished successfully.
    

    .NET Core SDK 3.1 安裝成功。

    3.5 安裝不受支持的版本 .NET 5.0

    官方文檔中,“.NET 5.0”在“不受支持”列表裡,它會否能安裝呢?於是我嘗試了一下。

    ubuntu@ip-175-76-22-54:~$ sudo ./dotnet-install.sh --channel 5.0
    dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
    dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
    dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
    dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
    
    dotnet-install: Attempting to download using aka.ms link https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.408/dotnet-sdk-5.0.408-linux-arm64.tar.gz
    dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.408/dotnet-sdk-5.0.408-linux-arm64.tar.gz
    dotnet-install: Installed version is 5.0.408
    dotnet-install: Adding to current process PATH: `/root/.dotnet`. Note: This change will be visible only when sourcing script.
    dotnet-install: Note that the script does not resolve dependencies during installation.
    dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
    dotnet-install: Installation finished successfully.
    

    .NET SDK 5.0 安裝成功。
    看來“不受支持”僅是指沒有技術支持,還是可以用 dotnet-install 腳本安裝該版本的。

    3.6 查看.NET SDK信息

    裝好了,想查看一下安裝的SDK信息,於是執行了以下命令。

    ubuntu@ip-175-76-22-54:~$ dotnet --list-sdks
    dotnet: command not found
    

    報錯了,找不到命令。
    原來是它沒被自動加到環境變數,故需要寫全路徑。

    ubuntu@ip-175-76-22-54:~$ /root/.dotnet/dotnet --list-sdks
    -bash: /root/.dotnet/dotnet: Permission denied
    

    這次遇到了“Permission denied”報錯。
    看來是跟先前的“sudo”安裝有關,需要使用“sudo”才能執行它。

    ubuntu@ip-175-76-22-54:~$ sudo /root/.dotnet/dotnet --list-sdks
    3.1.425 [/root/.dotnet/sdk]
    5.0.408 [/root/.dotnet/sdk]
    6.0.403 [/root/.dotnet/sdk]
    7.0.100 [/root/.dotnet/sdk]
    
    ubuntu@ip-175-76-22-54:~$ sudo /root/.dotnet/dotnet --info
    .NET SDK:
     Version:   7.0.100
     Commit:    e12b7af219
    
    Runtime Environment:
     OS Name:     ubuntu
     OS Version:  22.04
     OS Platform: Linux
     RID:         ubuntu.22.04-arm64
     Base Path:   /root/.dotnet/sdk/7.0.100/
    
    Host:
      Version:      7.0.0
      Architecture: arm64
      Commit:       d099f075e4
    
    .NET SDKs installed:
      3.1.425 [/root/.dotnet/sdk]
      5.0.408 [/root/.dotnet/sdk]
      6.0.403 [/root/.dotnet/sdk]
      7.0.100 [/root/.dotnet/sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 3.1.31 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 5.0.17 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 6.0.11 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 7.0.0 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 3.1.31 [/root/.dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 5.0.17 [/root/.dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 6.0.11 [/root/.dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 7.0.0 [/root/.dotnet/shared/Microsoft.NETCore.App]
    
    Other architectures found:
      None
    
    Environment variables:
      Not set
    
    global.json file:
      Not found
    
    Learn more:
      https://aka.ms/dotnet/info
    
    Download .NET:
      https://aka.ms/dotnet/download
    

    成功得到了安裝信息。

    四、運行 .NET 程式

    在Windows系統中,可方便的雙擊運行 .NET 程式;或是在命令行里直接輸入程式的exe文件名,來運行程式。
    而在非Windows系統中,需要通過 dotnet 命令來運行 .NET 程式。且命令行參數里不是傳遞主程式的exe文件名,而應該傳遞主程式的dll文件名。
    詳見官方文檔,摘錄:

    運行應用程式:
    
    .NET CLI
    dotnet [--additionalprobingpath <PATH>] [--additional-deps <PATH>]
        [--fx-version <VERSION>]  [--roll-forward <SETTING>]
        <PATH_TO_APPLICATION> [arguments]
    
    dotnet exec [--additionalprobingpath] [--additional-deps <PATH>]
        [--depsfile <PATH>]
        [--fx-version <VERSION>]  [--roll-forward <SETTING>]
        [--runtimeconfig <PATH>]
        <PATH_TO_APPLICATION> [arguments]
    

    4.1 運行 .NET 7.0 程式

    可以在其他電腦上開發程式,然後將編譯後的文件,拷貝到ARM伺服器上再運行。平臺(Platform)選 AnyCPU 就行,無需特意選 ARM64。且不用發佈(Publish),直接將“bin”文件夾下的 Debug或Release目錄 拷貝過去就行。
    於是我將前段時間開發的 VectorClassDemo 程式拷貝了過去,順便能檢查一下 .NET 對ARM的內在函數的支持性。將該程式分別用 .NET 5.0/7.0編譯一下,然後拷貝過去。

    若想將文件拷貝到遠程的伺服器上,可以用 scp 等命令。或者可以用RDP遠程桌面連接過去,在本機複製文件,然後在遠程桌面的文件管理器中粘貼,便能將文件複製過去。
    文件複製成功後,進入程式所在目錄,然後便可以用 dotnet 命令來執行程式了。例如我的這個程式的主程式的dll文件名為“VectorClassDemo50.dll”,於是語句為“sudo /root/.dotnet/dotnet ./VectorClassDemo50.dll”。
    20221126164739_run_dotnet.png

    輸出信息摘錄如下:

    ubuntu@ip-175-76-22-54:~/Documents/VectorClassDemo50/net7.0$ sudo /root/.dotnet/dotnet ./VectorClassDemo50.dll
    VectorClassDemo50
    
    IsRelease:	True
    EnvironmentVariable(PROCESSOR_IDENTIFIER):	
    Environment.ProcessorCount:	2
    Environment.Is64BitOperatingSystem:	True
    Environment.Is64BitProcess:	True
    Environment.OSVersion:	Unix 5.15.0.1023
    Environment.Version:	7.0.0
    RuntimeEnvironment.GetRuntimeDirectory:	/root/.dotnet/shared/Microsoft.NETCore.App/7.0.0/
    RuntimeInformation.FrameworkDescription:	.NET 7.0.0
    BitConverter.IsLittleEndian:	True
    IntPtr.Size:	8
    Vector.IsHardwareAccelerated:	True
    Vector<byte>.Count:	16	# 128bit
    Vector<T>.Assembly.CodeBase:	file:///root/.dotnet/shared/Microsoft.NETCore.App/7.0.0/System.Private.CoreLib.dll
    
    [Intrinsics.Arm]
    AdvSimd.IsSupported:	True
    AdvSimd.Arm64.IsSupported:	True
    Aes.IsSupported:	True
    Aes.Arm64.IsSupported:	True
    ArmBase.IsSupported:	True
    ArmBase.Arm64.IsSupported:	True
    Crc32.IsSupported:	True
    Crc32.Arm64.IsSupported:	True
    Dp.IsSupported:	True
    Dp.Arm64.IsSupported:	True
    Rdm.IsSupported:	True
    Rdm.Arm64.IsSupported:	True
    Sha1.IsSupported:	True
    Sha1.Arm64.IsSupported:	True
    Sha256.IsSupported:	True
    Sha256.Arm64.IsSupported:	True
    
    -- Single, Vector<Single>.Count=4 --
    srcT:	<-3.4028235E+38, Infinity, NaN, -1.2>	# (FF7FFFFF 7F800000 FFC00000 BF99999A)
    srcAllOnes:	<NaN, NaN, NaN, NaN>	# (FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF)
    Abs(srcT):	<3.4028235E+38, Infinity, NaN, 1.2>	# (7F7FFFFF 7F800000 7FC00000 3F99999A)
    

    可以看到:

    • 該程式正確的以“64位 .NET 7.0 程式”的方式在運行。
    • 向量類型支持硬體加速(Vector.IsHardwareAccelerated),且向量類型的長度為 128bit。這是因為ARM的 AdvSimd 指令集的數據長度最長為128位。
    • 目前的所有ARM內在函數(Intrinsics.Arm)的IsSupported都是true,表示都支持。

    4.2 運行 .NET 5.0 程式

    隨後又嘗試運行了 .NET 5.0編譯的程式。

    ubuntu@ip-175-76-22-54:~/Documents/VectorClassDemo50/net5.0$ sudo /root/.dotnet/dotnet ./VectorClassDemo50.dll
    VectorClassDemo50
    
    IsRelease:	True
    EnvironmentVariable(PROCESSOR_IDENTIFIER):	
    Environment.ProcessorCount:	2
    Environment.Is64BitOperatingSystem:	True
    Environment.Is64BitProcess:	True
    Environment.OSVersion:	Unix 5.15.0.1023
    Environment.Version:	5.0.17
    RuntimeEnvironment.GetRuntimeDirectory:	/root/.dotnet/shared/Microsoft.NETCore.App/5.0.17/
    RuntimeInformation.FrameworkDescription:	.NET 5.0.17
    BitConverter.IsLittleEndian:	True
    IntPtr.Size:	8
    Vector.IsHardwareAccelerated:	True
    Vector<byte>.Count:	16	# 128bit
    Vector<T>.Assembly.CodeBase:	file:///root/.dotnet/shared/Microsoft.NETCore.App/5.0.17/System.Private.CoreLib.dll
    
    [Intrinsics.Arm]
    AdvSimd.IsSupported:	True
    AdvSimd.Arm64.IsSupported:	True
    Aes.IsSupported:	True
    Aes.Arm64.IsSupported:	True
    ArmBase.IsSupported:	True
    ArmBase.Arm64.IsSupported:	True
    Crc32.IsSupported:	True
    Crc32.Arm64.IsSupported:	True
    Dp.IsSupported:	False
    Dp.Arm64.IsSupported:	False
    Rdm.IsSupported:	False
    Rdm.Arm64.IsSupported:	False
    Sha1.IsSupported:	True
    Sha1.Arm64.IsSupported:	True
    Sha256.IsSupported:	True
    Sha256.Arm64.IsSupported:	True
    
    -- Single, Vector<Single>.Count=4 --
    srcT:	<-3.4028235E+38, Infinity, NaN, -1.2>	# (FF7FFFFF 7F800000 FFC00000 BF99999A)
    srcAllOnes:	<NaN, NaN, NaN, NaN>	# (FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF)
    Abs(srcT):	<3.4028235E+38, Infinity, NaN, 1.2>	# (7F7FFFFF 7F800000 7FC00000 3F99999A)
    

    發現用 .NET 5.0 運行時,部分ARM內在函數是不被支持的,例如 Dp、Rdm。
    而之前查看 cpuinfo信息 時,Features里有 asimddp、asimdrdm,且剛纔用 .NET 7.0 測試時是支持的。看來硬體是支持的,只是 .NET 5.0 軟體不支持而已。
    即:雖然 .NET 5.0 定義了ARM內在函數,但是在某些平臺上的.NET 5.0運行時,沒能支持所有的內在函數。直到 .NET 7.0,才全部解決了內在函數的支持性問題。

    參考文獻

    作者:zyl910 出處:http://www.cnblogs.com/zyl910/ 版權聲明:自由轉載-非商用-非衍生-保持署名 | Creative Commons BY-NC-ND 3.0.
    您的分享是我們最大的動力!

    -Advertisement-
    Play Games
    更多相關文章
    • 理解多態 多種多樣的形態(靜態多態,動態多態) 靜態多態(編譯時期) 1:函數重載 bool comparet(int ,int); bool compare(double,double); compare(100,100)->compare_int_int(); compare(1.0,2.0)- ...
    • 打包下載成.zip文件 項目背景 公司使用vue + SpringBoot實現批量下載功能 今天在調試批量下載這個功能。打包成.zip文件時,在返回給前端瀏覽器出現報錯信息: 後端報錯: ERROR c.c.p.c.e.BusinessExceptionHandler - java.io.IOExc ...
    • 抽象類和普通類有什麼區別? 抽象類一般不用作抽象實體類型 一般把上面類設計為抽象類? 基類 定義抽象類的唯一目的, 就是去建立派生類. 我們在抽象類基礎上要定義出功能各異的派生類, 再用這些派生類去建立對象. 凡是包含純虛函數的類都是抽象類. 純虛函數不用實現, 故不能被調用, 抽象類無法建立對象. ...
    • JZ12 矩陣中的路徑 描述 請設計一個函數,用來判斷在一個n乘m的矩陣中是否存在一條包含某長度為len的字元串所有字元的路徑。路徑可以從矩陣中的任意一個格子開始,每一步可以在矩陣中向左,向右,向上,向下移動一個格子。如果一條路徑經過了矩陣中的某一個格子,則該路徑不能再進入該格子。 思路 我們看到他 ...
    • 本篇文章我們將進一步探討下Guava Cache 實現層面的一些邏輯與設計策略,讓我們可以對Guava Cache整體有個更加明朗的認識,促進實際使用中對其的理解。 ...
    • 問題:是不是虛函數的調用就一定是動態綁定?不是的 1:在類的構造函數當中,調用虛函數,也是靜態綁定(構造函數中對虛函數的調用不發生動態綁定) 2:如果不是通過指針或者引用變數來調用虛函數,那就是靜態綁定 代碼1 class Base { public: Base(int data=10):ma(da ...
    • 使用Apache PDFBox實現拆分、合併PDF 問題背景 如何拆分PDF? 如何合併PDF? 如何拆分併合並PDF實現去除PDF的某些頁? Apache PDFBox介紹 Apache PDFBox 1.8.10官方文檔 Apache PDFBox 庫是一個開源的 Java 工具,用於處理 PD ...
    • 作者:小牛呼嚕嚕 | https://xiaoniuhululu.com 電腦內功、JAVA源碼、職業成長、項目實戰、面試相關資料等更多精彩文章在公眾號「小牛呼嚕嚕」 前言 讀過筆者之前的一篇文章Java記憶體模型(JMM)詳解, 我們知道了由於電腦為了充分利用CPU的高性能,以及各個硬體 存取速 ...
    一周排行
      -Advertisement-
      Play Games
    • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
    • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
    • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
    • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
    • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
    • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
    • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
    • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
    • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
    • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...