delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/05/18/19:46:41

Date: Wed, 18 May 94 16:11:36 cst
From: rothfusza AT osprey DOT nwrc DOT gov
Encoding: 2059 Text
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Ver. 1.10 question about new[]

     Problem Statement:
     
        The following code is supposed to test the virtual memory
        capability of djgpp go32 v. 1.10 by allocating more memory than I
        have.
     
        The program causes a cold reboot of my machine at various points in 
        the array initialization loop, depending upon how much EMS I have 
        reserved via EMM386.
     
     Requested Info:
     
        Why does it crash and why does it depend upon the amount of EMS?
     
     System Info:
     
        i486DX/66
        16MB RAM
        300MB Free on disk
        DOS 5
        using 4DOS
        EMM386 settings:
                DEVICE=C:\WINDOWS\EMM386.EXE ON M9 X=CC00-CfFF 8000 RAM
                REM This provides about 8MB of EMS, which causes the 
                REM program to crash soon after the 7*1024*1024th element 
                REM of ra[] is initialized.
     
        With 2MB EMS, program crashes after 5*MEG
        With 12MB EMS, program crashes after 8*MEG
        Providing more or fewer FILES handles does not change anything.
     
     compile line:
        gcc -o memtest.g32 memtest.cc -lgpl
     
     Code:-----------------------------------------------------
     
     #include <iostream.h>
     #define MEG (1024L*1024L)
     void main(){
        long* ra;
        long sz=MEG*10L;
        long i;
        cout<<"about to new "<<sizeof(long)*sz<<endl;
        ra=0;
        ra=new long[sz];
        if(ra!=0){
                cout<<"Supposedly a success..."<<endl;
                for(i=0;i<sz;i++){
                        if((i%MEG)==0)cout<<i<<"/"<<sz<<endl;
                        ra[i]=i;
                }
                cout<<"Initialized."<<endl;
                for(i=sz-1;i>=0;i--){
                        if((i%10000L)==0)cout<<i<<"/"<<sz<<endl;
                        if(ra[i]!=i)cout<<"AAAA! "<<i<<endl;
                }
        }
        else cout<<"Rats!"<<endl;
        delete [] ra;
     }
     
     // advTHANKSance, andy++

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019