在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
    • 1、預覽地址:http://139.155.137.144:9012 2、qq群:801913255 一、前言 隨著網路的發展,企業對於信息系統數據的保密工作愈發重視,不同身份、角色對於數據的訪問許可權都應該大相徑庭。 列如 1、不同登錄人員對一個數據列表的可見度是不一樣的,如數據列、數據行、數據按鈕 ...
    • 前言 上一篇文章寫瞭如何使用RabbitMQ做個簡單的發送郵件項目,然後評論也是比較多,也是準備去學習一下如何確保RabbitMQ的消息可靠性,但是由於時間原因,先來說說設計模式中的簡單工廠模式吧! 在瞭解簡單工廠模式之前,我們要知道C#是一款面向對象的高級程式語言。它有3大特性,封裝、繼承、多態。 ...
    • Nodify學習 一:介紹與使用 - 可樂_加冰 - 博客園 (cnblogs.com) Nodify學習 二:添加節點 - 可樂_加冰 - 博客園 (cnblogs.com) 介紹 Nodify是一個WPF基於節點的編輯器控制項,其中包含一系列節點、連接和連接器組件,旨在簡化構建基於節點的工具的過程 ...
    • 創建一個webapi項目做測試使用。 創建新控制器,搭建一個基礎框架,包括獲取當天日期、wiki的請求地址等 創建一個Http請求幫助類以及方法,用於獲取指定URL的信息 使用http請求訪問指定url,先運行一下,看看返回的內容。內容如圖右邊所示,實際上是一個Json數據。我們主要解析 大事記 部 ...
    • 最近在不少自媒體上看到有關.NET與C#的資訊與評價,感覺大家對.NET與C#還是不太瞭解,尤其是對2016年6月發佈的跨平臺.NET Core 1.0,更是知之甚少。在考慮一番之後,還是決定寫點東西總結一下,也回顧一下.NET的發展歷史。 首先,你沒看錯,.NET是跨平臺的,可以在Windows、 ...
    • Nodify學習 一:介紹與使用 - 可樂_加冰 - 博客園 (cnblogs.com) Nodify學習 二:添加節點 - 可樂_加冰 - 博客園 (cnblogs.com) 添加節點(nodes) 通過上一篇我們已經創建好了編輯器實例現在我們為編輯器添加一個節點 添加model和viewmode ...
    • 前言 資料庫併發,數據審計和軟刪除一直是數據持久化方面的經典問題。早些時候,這些工作需要手寫複雜的SQL或者通過存儲過程和觸發器實現。手寫複雜SQL對軟體可維護性構成了相當大的挑戰,隨著SQL字數的變多,用到的嵌套和複雜語法增加,可讀性和可維護性的難度是幾何級暴漲。因此如何在實現功能的同時控制這些S ...
    • 類型檢查和轉換:當你需要檢查對象是否為特定類型,並且希望在同一時間內將其轉換為那個類型時,模式匹配提供了一種更簡潔的方式來完成這一任務,避免了使用傳統的as和is操作符後還需要進行額外的null檢查。 複雜條件邏輯:在處理複雜的條件邏輯時,特別是涉及到多個條件和類型的情況下,使用模式匹配可以使代碼更 ...
    • 在日常開發中,我們經常需要和文件打交道,特別是桌面開發,有時候就會需要載入大批量的文件,而且可能還會存在部分文件缺失的情況,那麼如何才能快速的判斷文件是否存在呢?如果處理不當的,且文件數量比較多的時候,可能會造成卡頓等情況,進而影響程式的使用體驗。今天就以一個簡單的小例子,簡述兩種不同的判斷文件是否... ...
    • 前言 資料庫併發,數據審計和軟刪除一直是數據持久化方面的經典問題。早些時候,這些工作需要手寫複雜的SQL或者通過存儲過程和觸發器實現。手寫複雜SQL對軟體可維護性構成了相當大的挑戰,隨著SQL字數的變多,用到的嵌套和複雜語法增加,可讀性和可維護性的難度是幾何級暴漲。因此如何在實現功能的同時控制這些S ...