各位高手请为小弟指点下,我用VC++6.0 写程序,就申请了1.2M空间,用该数组坐标访问特定的值是总报:Unhandled exception in newTrack2Program.exe:0xC0000005:Access Violation
程序代码:typedef struct InvertIndex
{
int ID;
struct InvertIndex* next;
}* PinvertIndex;PinvertIndex* invertIndex=new PinvertIndex[300000];//共动态申请1.2M空间int main()
{
  if(invertIndex!=NULL)
  {
  invertIndex[250000]->ID=100;
  }
  return 0;
}

解决方案 »

  1.   

    视系统内存而定,不过有国外的作者说,可以申请大于系统内存很多倍的内存空间,??
    invertIndex[250000]->ID=100;
    改成
    invertIndex[250000].ID=100;
      

  2.   

    PinvertIndex* invertIndex=new PinvertIndex[300000]
    你只是申请了一大堆invertIndex结构的指针而已,invertIndex[250000]->ID当然会非法访问了。
    PinvertIndex invertIndex=new InvertIndex[300000];
    这样才对
      

  3.   

    32位程序一般最多一次可以申请512MB空间,而且不能申请2个512MB那么大的,没有那么多连续地址空间。
      

  4.   

    不是定义大了,是你定义结构体变量的时候错了
    typedef struct InvertIndex
    {
    int ID;
    struct InvertIndex* next;
    }InvertIndex, *PinvertIndex;PinvertIndex invertIndex=new InvertIndex[300000];//¹²¶¯Ì¬ÉêÇë1.2M¿Õ¼äint main()
    {
     
    if(invertIndex!=NULL)
    {
    invertIndex[250000].ID=100;
    }
    return 0;
    }
      

  5.   

    typedef struct InvertIndex
    {
    int ID;
    struct InvertIndex* next;
    }InvertIndex, *PinvertIndex;PinvertIndex invertIndex=new InvertIndex[300000];
    int main()
    {
     
        if(invertIndex!=NULL)
        {
            invertIndex[250000].ID=100;
        }
        return 0;
    }
      

  6.   

    PinvertIndex* invertIndex=new PinvertIndex[300000]
    你只是申请了一大堆invertIndex结构的指针而已,invertIndex[250000]->ID当然会非法访问了。
    PinvertIndex invertIndex=new InvertIndex[300000];
    这样才对对楼上所言既是
      

  7.   

    小弟,谢谢楼上的各位仁兄了,小弟有一点不解的是有些时候空间明明分配了出去,但是读的时候会出现冲突!这个就此结贴吧!http://topic.csdn.net/u/20110622/22/6583cbfb-5b7f-45a2-8986-6201244d27e5.html?seed=1755134141&r=73994623#r_73994623,这是小弟的另外一贴,请各位大虾指教,讨论!
      

  8.   

    PinvertIndex invertIndex=new InvertIndex[300000];