473,387 Members | 1,440 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,387 software developers and data experts.

size of array XXX is too large

I need a large 3D array of structures:

struct s {
char a[40];
int b;
};
s s_array[10000][10000][100];

s_array is declared as global.

Unfortunatelly, when compiling, I get an error: "size of array
's_array' is too large"
(using GCC, but I think it doesn't matter)

But I have read, that global variables can be very large. Is it true?
And how can I make it in other way?

Thank you for answers.

Mar 21 '06 #1
7 21234
* ultr:
I need a large 3D array of structures:

struct s {
char a[40];
int b;
};
s s_array[10000][10000][100];

s_array is declared as global.

Unfortunatelly, when compiling, I get an error: "size of array
's_array' is too large"
(using GCC, but I think it doesn't matter)
Try to compute the size of your array assuming s is 42 bytes.

Hint: when you multiply by 10, just add a zero at the end of the number.

But I have read, that global variables can be very large. Is it true?
Yes.

And how can I make it in other way?


Smaller, or, wait a few years.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 21 '06 #2
ultr wrote:
I need a large 3D array of structures:

struct s {
char a[40];
int b;
};
s s_array[10000][10000][100];

s_array is declared as global.

Unfortunatelly, when compiling, I get an error: "size of array
's_array' is too large"
(using GCC, but I think it doesn't matter)

But I have read, that global variables can be very large. Is it true?
And how can I make it in other way?


You can allocate static storage for variables, and it can generally be
larger since it's not allocated <ot>on the stack</ot> like automatic
variables. You could also use dynamic memory allocation (new/delete or
malloc/free) to achieve the same goal.

However, your array *is* very large, and on a typical 32-bit system it
would be (10^10)*(40+4) = 440000000000 = 0x66720B3000 which is well
beyond 32-bit pointer ranges. (Are you writing exclusively for 64-bit
machines or better?)

You could solve this problem in any number of ways. One is to access
the array in chunks so you only use part of that memory at any one
time. Another would be to break up your array behind some abstraction.
Etc. Etc. Give us a better idea of what you're doing, and perhaps we
can make some better suggestions.

Cheers! --M

Mar 21 '06 #3
ultr wrote:
I need a large 3D array of structures:

struct s {
char a[40];
int b;
};
s s_array[10000][10000][100];

s_array is declared as global.

Unfortunatelly, when compiling, I get an error: "size of array
's_array' is too large"
(using GCC, but I think it doesn't matter)

But I have read, that global variables can be very large. Is it true?
And how can I make it in other way?

Thank you for answers.


Think about how much space you're asking for. sizeof(s) is at least 40
(more actually, but I like round numbers). s_array has 10000 * 10000 *
100 = 10^10 elements. So you're asking for at least 400GB of memory. I
think you need more RAM or a better algorithm.
Mar 21 '06 #4
ultr wrote:
I need a large 3D array of structures:

struct s {
char a[40];
int b;
};
s s_array[10000][10000][100];

s_array is declared as global.

Unfortunatelly, when compiling, I get an error: "size of array
's_array' is too large"
(using GCC, but I think it doesn't matter)
Do you actually have enough memory? Do you have a 64 bit platform. 32 bit
ones usually can only handle memory blocks of up to 4 GB size, which is by
far not enough for your array.
But I have read, that global variables can be very large. Is it true?
And how can I make it in other way?


Instead of holding hundreds of gigabytes in memory, you should have them on
disk and only load the parts currently needed. You probably need some
clever caching.

Mar 21 '06 #5
JE

ultr wrote:
I need a large 3D array of structures:

struct s {
char a[40];
int b;
};
s s_array[10000][10000][100];


<snip>

If your data is sparse, you could use a map instead of an array.

Best regards, JE

Mar 21 '06 #6


Instead of holding hundreds of gigabytes in memory, you should have them
on
disk and only load the parts currently needed. You probably need some
clever caching.


I don't think most of us even _have_ over 400gig of hard drive space.
Drives that big are pretty new, aren't they? (I'd suggest he find another
solution entirely.)

-Howard
Mar 22 '06 #7
Howard wrote:
Instead of holding hundreds of gigabytes in memory, you should have them
on
disk and only load the parts currently needed. You probably need some
clever caching.

I don't think most of us even _have_ over 400gig of hard drive space.
Drives that big are pretty new, aren't they? (I'd suggest he find another
solution entirely.)

You never know, he might be running on a SunFire server with 570Gb of RAM...

--
Ian Collins.
Mar 22 '06 #8

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

Similar topics

11
by: eggie2486 | last post by:
What is the maximum size of an array? I tried to edit an extremely large array for a magic square, for example, array, and when I ran the program, it would not display the array. I changed the...
13
by: HappyHippy | last post by:
Hi, I'm wondering what you think about this piece of code: #include<iostream> int main() { int size; std::cin >> size;
2
by: p175 | last post by:
Hi folks, I've tried reading just about every post I can on raid stiping / extent size etc and I'm just getting myself more confused than ever. Here's my situation. On a Windows Server 2000...
5
by: news.microsoft.com | last post by:
Hello, what is the most performant size for the byte array for reading/writing using 2 filestreams? example code: Dim bytearrayinput(4095) As Byte Dim rdlen As Long = 0 Dim totlen As Long...
11
by: shreesh | last post by:
I want to use an array of size greater than ARRAY but am getting an array size too large error. I am using a BC 3.1 on msdos ver 5.1.2600 on XP. How can i get around this simple but irritating...
5
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
2
by: kaczmar2 | last post by:
I have code like so: FileStream fs = new FileStream(locationTextBox.Text, FileMode.Open, FileAccess.Write, FileShare.Read); long size = fs.Length; byte buffer = new byte; // Get file to byte...
16
by: danieleghisi | last post by:
Hello I'm writing a small programme to look for some particular integer sets (homometric sets), and each one of this sets is a unsigned long long (e.g. {1, 2, 4, 7} --1001011=75). I need to have...
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.