473,404 Members | 2,114 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,404 software developers and data experts.

Very big arrays

Hello,

I'm trying to make a dll with some stored values, looking to store
several million doubles in a static array like this:

double delta[x_size][y_size][z_size];
void delta_init() {
delta[0][0][0] = 8.65;
delta[0][0][1] = 1.35;
delta[0][0][2] = 2.11;
delta[0][0][3] = 3.29;
delta[0][0][4] = 5.147;

etc ...

I'm trying to compile the code under Visual C++ Pro 2005, and the code
just does not compile - it runs over 10 hours and just hands there. I
was able to compile smaller arrays though.

How can I make the code compile? What is a better way to do this?
Thank you for your advice.

Dec 12 '06 #1
11 2238

victorg...@gmail.com skrev:
Hello,

I'm trying to make a dll with some stored values, looking to store
several million doubles in a static array like this:

double delta[x_size][y_size][z_size];
void delta_init() {
delta[0][0][0] = 8.65;
delta[0][0][1] = 1.35;
delta[0][0][2] = 2.11;
delta[0][0][3] = 3.29;
delta[0][0][4] = 5.147;

etc ...

I'm trying to compile the code under Visual C++ Pro 2005, and the code
just does not compile - it runs over 10 hours and just hands there. I
was able to compile smaller arrays though.
It must be a program with millions of lines, then?
>
How can I make the code compile? What is a better way to do this?
Thank you for your advice.
Technically it haven't failed yet, but I don't want to bet that the
compile will eventually succeed. But your question is platform
specific, so it is off-topic here. Go visit some group where you would
be on topic - perhaps microsoft.public.vc.language?

/Peter

Dec 12 '06 #2

vi********@gmail.com wrote:
Hello,

I'm trying to make a dll with some stored values, looking to store
several million doubles in a static array like this:

double delta[x_size][y_size][z_size];
void delta_init() {
delta[0][0][0] = 8.65;
delta[0][0][1] = 1.35;
delta[0][0][2] = 2.11;
delta[0][0][3] = 3.29;
delta[0][0][4] = 5.147;

etc ...

I'm trying to compile the code under Visual C++ Pro 2005, and the code
just does not compile - it runs over 10 hours and just hands there. I
was able to compile smaller arrays though.

How can I make the code compile? What is a better way to do this?
Thank you for your advice.
lol, 10 hours? Why would you store values in a dll? Wouldn't that eat
away at memory available to your program - dll must be loaded in mem?
Have you considered storing these in a file or several files? Or
perhaps develop an algorithm to initialize the values? Do you realize
that an array requires contiguous memory? Why don't you store related
values together in a struct/class and store instances of the
struct/class instead?

If i had to store points, for example, with an x, y and a z:

#include <iostream>
#include <ostream>
#include <vector>
#include <deque>

template< typename T >
struct Point
{
// universal ctor
Point(const T& x_ = T(),
const T& y_ = T(),
const T& z_ = T())
: x(x_), y(y_), z(z_) { }
// copy ctor
Point(const Point& copy)
{
x = copy.x;
y = copy.y;
z = copy.z;
}
private:
T x, y, z;
};

int main() {
// one million Points as doubles, all set to 0.0
std::deque< Point< double dcontainer(1000000); // done

std::cout << "double container's size = ";
std::cout << dcontainer.size() * sizeof(Point< double >);
std::cout << std::endl;

// one million Points as floats, all set to 0.0
std::deque< Point< float fcontainer(1000000);

std::cout << "float container's size = ";
std::cout << fcontainer.size() * sizeof(Point< float >);
std::cout << std::endl;

return 0;
}

/* output on this platform:

double container's size = 24000000 // 24 MB
float container's size = 12000000 // 12 MB

*/

Dec 12 '06 #3
vi********@gmail.com wrote:
Hello,

I'm trying to make a dll with some stored values, looking to store
several million doubles in a static array like this:
Assuming sizeof(double)==8, several million doubles will
likely occupy several tens of MB. You really want a dll that
big?
double delta[x_size][y_size][z_size];
void delta_init() {
delta[0][0][0] = 8.65;
delta[0][0][1] = 1.35;
delta[0][0][2] = 2.11;
delta[0][0][3] = 3.29;
delta[0][0][4] = 5.147;

etc ...

I'm trying to compile the code under Visual C++ Pro 2005, and the code
just does not compile - it runs over 10 hours and just hands there. I
was able to compile smaller arrays though.
Take a look at the HDD light, perhaps the compiler ran out of
memory and started thrashing?
How can I make the code compile? What is a better way to do this?
Thank you for your advice.
What exactly disallows you to read this data from a file?

HTH,
- J.
Dec 12 '06 #4
Thank you Peter & Peter.

I have a function that is slow to compute, so I pre-compute the values
and store them in a dll to retrieve in real-time. Obviously computing
the values in real-time would make the dll too slow. Few megs of RAM
that I'll need to use for it are hardly an issue on most desktops. Am I
missing something?

Dec 12 '06 #5

vi********@gmail.com wrote:
Hello,

I'm trying to make a dll with some stored values, looking to store
several million doubles in a static array like this:

double delta[x_size][y_size][z_size];
void delta_init() {
delta[0][0][0] = 8.65;
delta[0][0][1] = 1.35;
delta[0][0][2] = 2.11;
delta[0][0][3] = 3.29;
delta[0][0][4] = 5.147;

etc ...

I'm trying to compile the code under Visual C++ Pro 2005, and the code
just does not compile - it runs over 10 hours and just hands there. I
was able to compile smaller arrays though.

How can I make the code compile? What is a better way to do this?
Thank you for your advice.
Why don't you use static initialization?

double delta[x_size][y_size][z_size] =
{
{
{
8.65,
1.35,
2.11,
Dec 12 '06 #6

Salt_Peter wrote:
lol, 10 hours? Why would you store values in a dll? Wouldn't that eat
away at memory available to your program - dll must be loaded in mem?
Have you considered storing these in a file or several files? Or
Especially if you store your numbers in a binary file, with fixed
record length, you may not even have to load the entire file into
memory (assuming disk access is fast enough for your purposes). You
could just seek to the values in the file and read them in, as you need
them. This way you could get away with using far less memory than a few
megabytes, or a few tens of megabytes.

Regards,
Markus.

Dec 12 '06 #7

vi********@gmail.com skrev:
Thank you Peter & Peter.

I have a function that is slow to compute, so I pre-compute the values
and store them in a dll to retrieve in real-time. Obviously computing
the values in real-time would make the dll too slow. Few megs of RAM
that I'll need to use for it are hardly an issue on most desktops. Am I
missing something?
Yes. If the purpose is simply to keep some precomputed values, it would
be much better to write those values to a file and read them back when
you need them (using a std::vector for flexibility).

/Peter

Dec 13 '06 #8

peter koch escreveu:
vi********@gmail.com skrev:
Thank you Peter & Peter.

I have a function that is slow to compute, so I pre-compute the values
and store them in a dll to retrieve in real-time. Obviously computing
the values in real-time would make the dll too slow. Few megs of RAM
that I'll need to use for it are hardly an issue on most desktops. Am I
missing something?
Yes. If the purpose is simply to keep some precomputed values, it would
be much better to write those values to a file and read them back when
you need them (using a std::vector for flexibility).

/Peter
I think you should store the precomputed values into a file and map
that file to memory. This is an OS feature, and by doing this, you
won´t have to worry about lots of the memory management specific
details.

Regards,
Henrique

Dec 13 '06 #9

Henrique Bastos skrev:
peter koch escreveu:
vi********@gmail.com skrev:
Thank you Peter & Peter.
>
I have a function that is slow to compute, so I pre-compute the values
and store them in a dll to retrieve in real-time. Obviously computing
the values in real-time would make the dll too slow. Few megs of RAM
that I'll need to use for it are hardly an issue on most desktops. AmI
missing something?
Yes. If the purpose is simply to keep some precomputed values, it would
be much better to write those values to a file and read them back when
you need them (using a std::vector for flexibility).

/Peter

I think you should store the precomputed values into a file and map
that file to memory. This is an OS feature, and by doing this, you
won´t have to worry about lots of the memory management specific
details.
Apart from non-portability and (probably) some faster load-time, I do
not see your method having an advantage.

/Peter
Regards,
Henrique
Dec 13 '06 #10

Hi,
I have the similar problem. It looks only occur on VC 2005
I have to compile a an 47K size array
UINT8 UIRES_FONTLIB_DATA_000[2774*16+5] =
{
0x00,0x00,0xad,0x61,/* file size of fontfile */
0x00,0x01,0x00,0x00,0x00,0x0b,0x00...}

I compile OK on all old VC build(6.0, or 7.0). but recently, I upgrade
my VC to VC2005 Express, then it failed to compile for this array.
takes too long to compile, I have to ctrl+break it.
if I cut the array shorter, then It compile OK too.

who can tell what's the problem? a bug of VC2005?

Thanks,
On 12ÔÂ13ÈÕ, ÏÂÎç10ʱ26·Ö, "peter koch"
<peter.koch.lar...@gmail.comwrote:
Henrique Bastos skrev:


peter koch escreveu:
victorg...@gmail.com skrev:
Thank you Peter & Peter.
I have a function that is slow to compute, so I pre-compute the values
and store them in a dll to retrieve in real-time. Obviously computing
the values in real-time would make the dll too slow. Few megs of RAM
that I'll need to use for it are hardly an issue on most desktops. Am I
missing something?
Yes. If the purpose is simply to keep some precomputed values, it would
be much better to write those values to a file and read them back when
you need them (using a std::vector for flexibility).
/Peter
I think you should store the precomputed values into a file and map
that file to memory. This is an OS feature, and by doing this, you
won¡ät have to worry about lots of the memory management specific
details.Apart from non-portability and (probably) some faster load-time, I do
not see your method having an advantage.

/Peter
Regards,
Henrique- Òþ²Ø±»ÒýÓÃÎÄ×Ö -- ÏÔʾÒýÓõÄÎÄ×Ö -- Òþ²Ø±»ÒýÓÃÎÄ×Ö -- ÏÔʾÒýÓõÄÎÄ×Ö -
Dec 25 '06 #11

ou***********@gmail.com skrev:
Hi,
I have the similar problem. It looks only occur on VC 2005
I have to compile a an 47K size array
UINT8 UIRES_FONTLIB_DATA_000[2774*16+5] =
{
0x00,0x00,0xad,0x61,/* file size of fontfile */
0x00,0x01,0x00,0x00,0x00,0x0b,0x00...}

I compile OK on all old VC build(6.0, or 7.0). but recently, I upgrade
my VC to VC2005 Express, then it failed to compile for this array.
takes too long to compile, I have to ctrl+break it.
if I cut the array shorter, then It compile OK too.

who can tell what's the problem? a bug of VC2005?
I believe it is. I recommend you take it to a microsoft group
(microsoft.public.vc.language if my memory serves me). There is a
service pack for the VC2005 Express - did you apply it? It just might
solve your problem.

/Peter

Dec 26 '06 #12

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

Similar topics

30
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
16
by: mamo74 | last post by:
Hello. I am administering a SQL Server (Enterprise Edition on Windows 2003) from some month and can't understand what is going on in the latest week (when the db grow a lot). The DB is around...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
6
by: Omid Hodjati | last post by:
Hi All, I implemented an encryption algorithm using C#, native C++ and managed C++. Then I measured the CPU time used for executing this algorithm in all implementation. The managed version of...
38
by: djhulme | last post by:
Hi, I'm using GCC. Please could you tell me, what is the maximum number of array elements that I can create in C, i.e. char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ; I've...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
58
by: mailursubbu | last post by:
Hi How to write a program to get the factorial of 4096. I am working on a Linux m/c. Best Regards, Subra
10
by: Peter Duniho | last post by:
This is kind of a question about C# and kind of one about the framework. Hopefully, there's an answer in there somewhere. :) I'm curious about the status of 32-bit vs 64-bit in C# and the...
1
by: tigerved | last post by:
Hi I am new to this so I dont exactly know the format in which to post the questions ....anyways here goes ...my file looks like this Year,Day,MOnth,latitude,longitude (commas included)...
4
by: cleanrabbit | last post by:
Hello! I hate having to do this, because im almost certain there is someone in the world that has come across this problem and i just havent found their solution yet, so i do appologise if this...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.