我可以用struct数组分配多少内存? [英] How much memory can I alloc with an array of struct ?

查看:65
本文介绍了我可以用struct数组分配多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过结构数组分配大量内存(最大为PC可以分配的内存)

请参见下面的示例:

I'm trying to allocate a huge amount(max as my PC can alloc) of memory with an array of struct

See the example below:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace struct_performance
{
  class Program
  {
    public struct Block
    {
      public string OrderId;
      public string OrderIdOrig;
      public string OrderIdInit;
      public string Symbol;
      public bool Side;
      public int Qty;
      public float Price;
      public string AccountId;
      public string Destination;
      public string Status;
      public string QtyExec;
      public float PriceAvg;
      public string ExchId;
      public string Msg;
      public string OrderTime;
      public string TimeStamp;
      public int OrderRow;
      public int MaxFloor;
      public int MaxShow;
      public string TimeInForce;
      public string OrdType;
    }

    static void Main(string[] args)
    {
      try
      {
        Console.ReadKey();
        Block[] blocks01 = new Block[9500000];
      }
      catch (Exception err)
      {
        Console.WriteLine(err.Message);
        if (!(err.InnerException == null))
          Console.WriteLine(err.InnerException.Message);
        Console.ReadKey();
      }
    }
  }
}

推荐答案

您的过程.地址空间的碎片越大,连续的地址空间就越少.您无法最大化内存,因为将可执行文件和dll加载到进程的地址中 空间会导致一些碎片.

It is limited by the continuous memory address space in your process. The more fragment your address space is, the less continuous address space you have. You cannot max out the memory, as loading your executable and dlls into the process's address space will cause some fragmentation to begin with.

如果32位地址空间不足以容纳您的应用,则应考虑转移到64位.

You should consider moving to 64bit if the 32bit address space is not enough for your apps. 


这篇关于我可以用struct数组分配多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆