home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12309 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  2.2 KB

  1. Path: sparky!uunet!olivea!news.bbn.com!noc.near.net!wpi.WPI.EDU!winton!ajb
  2. From: ajb@winton.uucp (Arthur J. Butler)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Allocating arrays larger than 64K with new?
  5. Message-ID: <BsxEsH.Eso@wpi.WPI.EDU>
  6. Date: 13 Aug 92 14:26:41 GMT
  7. References: <1992Aug9.152253.11345@newshub.sdsu.edu> <894@nazgul.UUCP> <f94m37_.feustel@netcom.com>
  8. Sender: news@wpi.WPI.EDU (USENET News System)
  9. Organization: Worcester Polytechnic Institute, MA
  10. Lines: 97
  11. Nntp-Posting-Host: winton.wpi.edu
  12.  
  13. In article <f94m37_.feustel@netcom.com> feustel@netcom.com (David Feustel) writes:
  14. >The following program compiles and links successfully with the ZTC
  15. >-mx option. Running the program crashes the system. The program was
  16. >linked and run under Flashtek's x32 dos extender.
  17. >
  18. >==============
  19. >
  20. >#include <stdio.h>
  21. >
  22. >#define AS 3000000
  23. >
  24. >long * getspace(unsigned int amount)
  25. >{    long * a;
  26. >    printf("malloc %d ",amount);
  27. >    if(a=(long *) malloc(sizeof(long)*amount))
  28. >    {    printf("succeeded\n");
  29. >
  30. >    else
  31. >
  32. >    {    printf("failed\n");
  33. >
  34. >    }
  35. >
  36. >    return a;
  37. >
  38. >}
  39. >
  40. >    
  41. >
  42. >
  43. >void main(int argc,char **argv)
  44. >
  45. >{    long i,imax=AS;
  46. >
  47. >    double sum=0;
  48. >
  49. >    long *a, *b, *c;
  50. >
  51. >    printf("Hello, World\n");
  52. >
  53. >    for(i=0;i<argc;++i)
  54. >
  55. >    {    printf("%s\n",argv[i]);
  56. >
  57. >    }
  58. >
  59. >    a=getspace(AS);
  60. >
  61. >    b=getspace(AS);
  62. >
  63. >    c=getspace(AS);
  64. >
  65. >    if (a==0|b==0|c==0) exit(-1);
  66. >
  67. >    for(i=0;i<imax;++i)
  68. >
  69. >    {    
  70. >
  71. >        a[i]=i*i;
  72. >
  73. >        b[i]=i;
  74. >
  75. >        c[i]=i*i*i;
  76. >
  77. >        sum+=a[i]+b[i]+c[i];
  78. >
  79. >    }
  80. >
  81. >    free(a); free(b); free(c);
  82. >
  83. >    printf("sum: %e\n",sum);
  84. >
  85. >    exit(0);
  86. >
  87. >}
  88. >
  89. >
  90. >-- 
  91. >Dave Feustel N9MYI <feustel@netcom.com>
  92. >---
  93. >Given Civil Seizure, from the DEA's point of view, winning the War on
  94. >Drugs would be killing the Goose that lays golden eggs.
  95.  
  96.  
  97. I just compiled this using Zortech and linking with x32v.lib.  I
  98. compiled it both as a C program and as a C++ program (minor note: i had to
  99. include stdlib.h).  I sucessfully ran it on my 486 with 8 meg of
  100. memory and about 80 meg of free disk space.  You are allocating three
  101. chunks of 12 Mbytes each.
  102.  
  103. I believe your problem is that you compiled the program in small
  104. memory model and not X memory model.  It will link with x32 and not
  105. complain at all.  I did that by mistake and indeed running the program
  106. halted the system.
  107.  
  108. arthur (ajb@winton.wpi.edu)
  109.