Tag: 记忆

C#应用程序可以使用多少RAM?

我有非常大的DataTable对象,非常大的数组等应用程序。 目前我的内存使用量低于2GB。 当我的应用程序在32位系统上生成4个1GB大小的arrays时会发生什么? 会崩溃吗? 我知道CLR中有2GB的对象大小限制,但是许多大对象呢? 我试图测试它,我宣布几个大数组,但当它们是空的时,他们似乎没有使用RAM。 我没试过填写它们,我决定在这里问一下。

传递方法参数的最佳内存方式

我的代码遇到了一些内存性能问题,我不确定将参数传递给我的方法的最佳方法。 我将举一个简短的例子。 我有这样的课: class Person { public string Name { get; set; } public bool IsMale { get; set; } public string Address { get; set; } public DateTime DateOfBirth { get; set; } } 然后我像这样使用它: static void Main(string[] args) { Person person = new Person { Name = “John”, Address = “Test address”, DateOfBirth […]

如何在C#中使用非常大的字典?

我想在C#应用程序中使用查找映射或字典,但是它应该存储1-2 GB的数据。 有人可以告诉我是否仍然可以使用字典类,或者我是否需要使用其他类? 编辑:我们有一个现有的应用程序,它使用oracle数据库来查询或查找对象详细信息。 然而它太慢了,因为相同的对象被反复查询。 我觉得在这种情况下使用查找映射可能是理想的,以改善响应时间。 但是我担心尺寸会不会成为问题

创建新类或结构时.NET中的内存使用情况

Int的大小为4个字节,如果我在程序中创建一个新的Int将使其内存消耗增加4个字节。 对? 但如果我有这门课 public class Dummy{ private int; } 我的新课程将使用多少内存? 如果是结构,内存消耗会更低吗? 我认为引用本身也会占用一些内存。

为什么拆箱比拳击快100倍

为什么装箱和拆箱操作之间的速度变化如此之大? 有10倍的差异。 我们什么时候应该关心这个? 上周,Azure支持人员告诉我们,我们的应用程序的堆内存存在问题。 我很想知道它是否与装箱拆箱问题有关。 using System; using System.Diagnostics; namespace ConsoleBoxing { class Program { static void Main(string[] args) { Console.WriteLine(“Program started”); var elapsed = Boxing(); Unboxing(elapsed); Console.WriteLine(“Program ended”); Console.Read(); } private static void Unboxing(double boxingtime) { Stopwatch s = new Stopwatch(); s.Start(); for (int i = 0; i < 1000000; i++) { int a […]

.Net中字符串(或任何其他对象)的内存使用情况

我写了这个小测试程序: using System; namespace GCMemTest { class Program { static void Main(string[] args) { System.GC.Collect(); System.Diagnostics.Process pmCurrentProcess = System.Diagnostics.Process.GetCurrentProcess(); long startBytes = pmCurrentProcess.PrivateMemorySize64; double kbStart = (double)(startBytes) / 1024.0; System.Console.WriteLine(“Currently using ” + kbStart + “KB.”); { int size = 2000000; string[] strings = new string[size]; for(int i = 0; i < size; i++) { […]

C#收益率回报表现

使用yield return语法的方法后面的底层集合保留了多少空间当我在其上执行ToList()时? 如果我创建一个具有预定义容量的列表的标准方法,它有可能重新分配并因此降低性能吗? 这两种情况: public IEnumerable GetList1() { foreach( var item in collection ) yield return item.Property; } public IEnumerable GetList2() { List outputList = new List( collection.Count() ); foreach( var item in collection ) outputList.Add( item.Property ); return outputList; }

我的记忆在哪里? 重新初始化DataTable

我有1个DataGridView,1个DataTable等应用程序。 我的“执行”方法(已编辑): private void btnRunSQL_click() { string strConnStr = tbConnStr.Text; // connection string from textbox string strSQL = tbSql.Text; // query from textbox SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strConnStr); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); // clean memory // dtData DataTable is declared in main form class dtData = new DataTable(); dataAdapter.Fill(dtData); showMemoryUsage(); } 这是我如何检查内存: public […]

直接返回值或创建临时变量之间的性能差异

与直接返回分配给此变量的值相比,在函数中创建临时变量是否存在任何性能损失或内存消耗差异? 例如,这些函数中的哪一个(GetValue)性能更好,节省内存或两者都完全相同: 情况1: private string GetValue() { return this.GetResult(); } private string GetResult() { // Code here that return a big string… } 案例2: private string GetValue() { string result = this.GetResult(); return result; } private string GetResult() { // Code here that return a big string… } 谢谢。

如何防止字符串被拦截

我的理解(可能是错误的)是在c#中创建一个字符串时它会被插入“实习池”。 这保持了对字符串的引用,以便多个相同的字符串可以共享操作内存。 但是我正在处理很多很可能是唯一的字符串,我需要在完成每个字符串之后将它们从操作内存中完全删除,我不知道如何删除缓存的引用以便垃圾收集器可以从内存中删除所有字符串数据。 如何防止字符串在此缓存中被中断,或者如何清除它/从中删除字符串以便它确实从操作内存中删除?