473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help:How can I create a Huge array with 10000000 elements?

Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"

int main() {
int v[10000000];
long i;
for (i=1; i<=10000000; i++) v [ i ]=i;
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?

Thanks for your help.

Nov 15 '05 #1
18 3144

zehanw...@gmail.com wrote:
Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"

int main() {
int v[10000000];
long i;
for (i=1; i<=10000000; i++) v [ i ]=i;
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?
Because arrays index from 0?

Thanks for your help.


Nov 15 '05 #2
ze*******@gmail.com wrote:
Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"
If you want to include system headers, use angular brackets:

#include <stdio.h>
#include <stdlib.h>
int main() {
int v[10000000];
long i;
If you're indexing an array, size_t is a more suitable type than long,
although it's not wrong. (Hey, that rhymes.)
for (i=1; i<=10000000; i++) v [ i ]=i;
Your program accesses v[10000000], which is not part of the array. It
only goes up to v[9999999], since arrays start from 0 in C. Write the
loop like this:

for (i = 0; i < 10000000; i++) v[i] = i;

Or better yet (and look up the details of this if you don't understand it):

for (i = 0; i < sizeof v / sizeof v[0]; i++) v[i] = i;

Finally, note that the values you're trying to assign to the array
elements exceed the maximum value guaranteed to fit in an int (32767).
They will fit on a 32-bit platform, but it is still good to keep in
mind. If you want to make sure these values can be stored, make the type
of the array elements `long', not `int'; then it will work on any platform.
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?


Aside from the problems above, you're trying to use an array of 40
million bytes (I'm guessing you're compiling for a Win32 platform, which
has ints that are 4 bytes large). This exceeds the default stack of 1 MB
Visual C++ sets for applications.

If you *really* want your program to allocate 40 million bytes on
startup, tell the compiler that this should be allowed. Search for
"stack size" in the documentation. Failing that, make your array
smaller, or allocate it dynamically.

S.
Nov 15 '05 #3
ze*******@gmail.com writes:
Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"

int main() {
int v[10000000];
long i;
for (i=1; i<=10000000; i++) v [ i ]=i;
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?


What error occurred?

Some systems impose limits on how big a variable can be. You might be
able to allocate more space with malloc() than with a local variable
declaration, but there are no guarantees.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #4
Keith Thompson wrote:

ze*******@gmail.com writes:
Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"

int main() {
int v[10000000];
long i;
for (i=1; i<=10000000; i++) v [ i ]=i;
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?


What error occurred?


There was no visible output :)

--
pete
Nov 15 '05 #5
pete wrote:
Keith Thompson wrote:
ze*******@gmail.com writes:
Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"

int main() {
int v[10000000];
long i;
for (i=1; i<=10000000; i++) v [ i ]=i;
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?


What error occurred?

There was no visible output :)

Oh, I think he actually got one of those nice dialogue boxes that says
"Abort, retry, fail, ignore?"

Eh, slightly wrong OS. Never mind.

S.
Nov 15 '05 #6
On 2005-11-11, Skarmander <in*****@dontmailme.com> wrote:
pete wrote:
Keith Thompson wrote:
ze*******@gmail.com writes:

Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"

int main() {
int v[10000000];
long i;
for (i=1; i<=10000000; i++) v [ i ]=i;
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?

What error occurred?

There was no visible output :)

Oh, I think he actually got one of those nice dialogue boxes
that says "Abort, retry, fail, ignore?"

Eh, slightly wrong OS. Never mind.


I was hoping for: "Keyboard not found. Press any key to reboot."

--
Neil Cerutti
Nov 15 '05 #7
Neil Cerutti <le*******@email.com> writes:
On 2005-11-11, Skarmander <in*****@dontmailme.com> wrote:
pete wrote:
Keith Thompson wrote: [snip]What error occurred?
There was no visible output :)

Oh, I think he actually got one of those nice dialogue boxes
that says "Abort, retry, fail, ignore?"

Eh, slightly wrong OS. Never mind.


I was hoping for: "Keyboard not found. Press any key to reboot."


Press any key to continue. Press any other key to abort.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #8
Thanks for your help!

Nov 15 '05 #9
On 11 Nov 2005 21:41:50 +0100, in comp.lang.c , Neil Cerutti
<le*******@email.com> wrote:

I was hoping for: "Keyboard not found. Press any key to reboot."


The actual message with my mobo is
"Keyboard not found. Press any key to continue"

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #10
Mark McIntyre wrote:
On 11 Nov 2005 21:41:50 +0100, in comp.lang.c , Neil Cerutti
<le*******@email.com> wrote:

I was hoping for: "Keyboard not found. Press any key to reboot."

The actual message with my mobo is
"Keyboard not found. Press any key to continue"

Heh, mine is F1 (on my laptop), but on my server it says "No keyboard
present, ignoring.". Iirc it's a setting in the BIOS.
Nov 15 '05 #11
In article <u3********************************@4ax.com>,
Mark McIntyre <ma**********@spamcop.net> wrote:
The actual message with my mobo is
"Keyboard not found. Press any key to continue"


Much as I hate to spoil an excellent story, this message is not as
contradictory as it appears. You can find a keyboard, plug it in, and
press a key to continue.

-- Richard
Nov 15 '05 #12
In article <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> writes:
ze*******@gmail.com writes:
Compiler: Visual C++ 6.0
My code:
//==============================
# include "stdio.h"
# include "stdlib.h"

int main() {
int v[10000000];
long i;
for (i=1; i<=10000000; i++) v [ i ]=i;
return 0;
}
//==============================

No any errors or warnings while compiling or linking. But when I run
the executable file, an error ocured. WHY?


What error occurred?


I would expect something like a segmentation fault. When i == 10000000,
there is no associated array element. To the OP:
1. int v[5] declares an array that can be indexed from 0 to 5, v[5]
does not exist.
2. some systems restrict the amount of storage you may request in
local declarations (as here).
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 15 '05 #13
In article <dl***********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.uk> wrote:
In article <u3********************************@4ax.com>,
Mark McIntyre <ma**********@spamcop.net> wrote:
The actual message with my mobo is
"Keyboard not found. Press any key to continue"

Much as I hate to spoil an excellent story, this message is not as
contradictory as it appears. You can find a keyboard, plug it in, and
press a key to continue.


[OT]
No, usually you cannot do that. If you have a PS/2 keyboard, then
usually plugging it in while the system is running will -not- result
in the keyboard being recognized. If you have a USB keyboard, then
when you are at that place in the PROM, plugging in the USB is unlikely
to get the drivers selected and activated.

The one case I can think of in which plugging in the keyboard at that
point would work, was with the serial keyboards that are rarely used
anymore.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Nov 15 '05 #14
Possible Problems:
Prob: 1. You are running our of stack space. (99% possibility)
Sol: 1. Make the array global.
Prob: 2. You don't have that much of free memory.
Sol: 2. Ensure that you have about 40MB free memory.

Yes, indexing is a problem,
write either for (i=0; i<10000000; i++) or for (i=1; i<10000000;
i++) whichever suits your intentions.
Corrected:

# include "stdio.h"
# include "stdlib.h"

int v[10000000];
int main() {
long i;
for (i=0; i<10000000; i++) v [ i ]=i;
return 0;
}


--
Thanking you
আন্নািজয়াত আলীম রােসল
Annajiat Alim Rasel
Secretary
BUCC
BRAC University Computer Club
BUCC: http://groups-beta.google.com/group/bucc
BUCC Programming Contest Wing:
http://groups.yahoo.com/group/buacm
http://groups-beta.google.com/group/buacm

Nov 15 '05 #15
In article <dl**********@canopus.cc.umanitoba.ca>,
Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:
No, usually you cannot do that. If you have a PS/2 keyboard, then
usually plugging it in while the system is running will -not- result
in the keyboard being recognized.


You may well be right, it's a long time since I tried it and it was
probably a serial keyboard.

-- Richard
Nov 15 '05 #16
On 2005-11-13, Richard Tobin <ri*****@cogsci.ed.ac.uk> wrote:
In article <u3********************************@4ax.com>,
Mark McIntyre <ma**********@spamcop.net> wrote:
The actual message with my mobo is
"Keyboard not found. Press any key to continue"


Much as I hate to spoil an excellent story, this message is not
as contradictory as it appears. You can find a keyboard, plug
it in, and press a key to continue.


It depends on the port. Those darn PS2 ports can actually fry if
you hot-plug 'em. They aren't designed for that.

--
Neil Cerutti
Nov 15 '05 #17

Dik T. Winter wrote:
1. int v[5] declares an array that can be indexed from 0 to 5, v[5]
does not exist.


I think you meant indexed from 0 to 4 :-)

Nov 15 '05 #18
Neil Cerutti wrote:
On 2005-11-13, Richard Tobin <ri*****@cogsci.ed.ac.uk> wrote:
In article <u3********************************@4ax.com>,
Mark McIntyre <ma**********@spamcop.net> wrote:

The actual message with my mobo is
"Keyboard not found. Press any key to continue"


Much as I hate to spoil an excellent story, this message is not
as contradictory as it appears. You can find a keyboard, plug
it in, and press a key to continue.

It depends on the port. Those darn PS2 ports can actually fry if
you hot-plug 'em. They aren't designed for that.

And once you fry the keyboard conroller you're in for a new motherboard.
The replacement part costs as much as the mainboard and the labor to
replace costs more than either.

Don't hot-plug anything! Or, keep lots of money around.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 15 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eric in somewhere | last post by:
How to install J2SE 1.4.2 with NetBeans IDE on WindowsME? When I install it till 6%, a DOS window opened and then closed, then the process stop here. How can fix it? Please help.
6
by: ritagoldman101 | last post by:
Pls help - how to find Domain owner For most people this may be an easy question...but not for me. How can I find out who the owner of a domain is so I can write to her / him and ask if she /...
1
by: Alan & Sharron Brown | last post by:
'Help - How can you run 2 versions of Access on 1 pc' I would like to run Access 97 and Access 2003 on the same PC but have error
0
by: YiTian_Ken | last post by:
Help!!How to use MSMQ in WebForm? I can not send any Message from MSMQ?
6
by: hb | last post by:
Hi, Would you please tell me how to detect if the client's browser is closed? I need such event to trigger a database modification. Thank you hb
0
by: RSB | last post by:
Hi Every one, i am trying to create a UserControl and i am passing a Array of strings to it. Now based on the Array elements i am creating the LinkButtons Dynamically. I am also passing a Event to...
4
by: txican | last post by:
the HTML is: ---------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html> <head> <title>foo</title>...
4
by: jadeivel756 | last post by:
I BADLY NEED YOUR HELP...... HELP... hOW TO Pass value to a struct type and permanently store the data after youve given the data.The programming language is C. My problem is that as I exit the...
0
by: rafeig77 | last post by:
I want help How I can align rectangles differ in its tow dimensions inside big rectangle with lesser waste in area ? for mor information align.rar - 1.8 Kb or: copy this code to text file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.