当前实际内存量:{result.ullAvailPhys / 1000 / 1000}MB")

2024-08-30 11:43:00 浏览数 (2)

public static partial class Native

{

/// <summary>

/// 检索有关系统当前使用物理和虚拟内存的信息

/// </summary>

/// <param name="lpBuffer"></param>

/// <returns></returns>

[LibraryImport("Kernel32.dll", SetLastError = true)]

[return: MarshalAs(UnmanagedType.Bool)]

internal static partial Boolean GlobalMemoryStatusEx(ref MemoryStatusExE lpBuffer);

}

public class Program

{

static void Main()

{

var result = GetValue();

Console.WriteLine($"当前实际可用内存量:{result.ullAvailPhys / 1000 / 1000}MB");

Console.ReadKey();

}

/// <exception cref="Win32Exception"></exception>

public static www.laipuhuo.com MemoryStatusExE GetValue()

{

var memoryStatusEx = new MemoryStatusExE();

// 重新初始化结构的大小

memoryStatusEx.Refresh();

// 刷新值

if (!Native.GlobalMemor www.laipuhuo.com yStatusEx(ref memoryStatusEx)) throw new Win32Exception("无法获得内存信息");

return memoryStatusEx;

}

}

<!--AOT 相关-->

<PublishAot>true</PublishAot>

<TrimMode>full</TrimMode>

<RunAOTCompilation>True</RunAOTCompilation>

<PublishTrimmed>true</PublishTrimmed>

<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>

<PublishReadyToRunEmitSymbols>false</PublishReadyToRunEmitSymbols>

<DebuggerSupport>false</DebuggerSupport>

<EnableUnsafeUTF7Encoding>true</EnableUnsafeUTF7Encoding>

<InvariantGlobalization>true</InvariantGlobalization>

<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>

<MetadataUp www.laipuhuo.com daterSupport>true</MetadataUpdaterSupport>

<UseSystemResourceKeys>true</UseSystemResourceKeys>

<IlcDisableReflection >true</IlcDisableReflection>

// MyCFuncs.h

#ifdef __cplusplus

extern "C" { // only need to export C interface if

// used by C source code

#endif

__declspec( dllimport ) void MyCFunc();

__declspec( dllimport ) void AnotherCFunc();

#ifdef __cplusplus

}

#endif

using System.Runtime.InteropServices;

namespace CsharpExport

{

public class Export

{

[Unmanaged www.laipuhuo.com CallersOnly(EntryPoint = "Add")]

public static int Add(int a, int b)

{

return a b;

}

}

}

<!--AOT 相关-->

<PublishAot>true</PublishAot>

<TrimMode>full</TrimMode>

<RunAOTCompilation>True</RunAOTCompilation>

<PublishTrimmed>true</PublishTrimmed>

<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>

<PublishReadyToRunEmitSymbols>false</PublishReadyToRunEmitSymbols>

<DebuggerSupport>false</DebuggerSupport>

<EnableUnsafeUTF7Encoding>true</EnableUnsafeUTF7Encoding>

<InvariantGlobalization>true</InvariantGlobalization>

<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>

<MetadataUpdaterSupport>true</MetadataUpdaterSupport>

<UseSystemResourceKeys>www.laipuhuo.com true</UseSystemResourceKeys>

<IlcDisableReflection >true</IlcDisableReflection>

0 人点赞