473,395 Members | 1,624 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.

Array Creation - Error

mikejfe
12
Hi all.

I create an array using this code:
Expand|Select|Wrap|Line Numbers
  1. //Variables.h
  2. extern int *g_x;                                    //x voxel vector
  3. extern int *g_y;                                    //y voxel vector
  4. extern int *g_z;                                    //z voxel vector
  5. extern double ***g_xyz;                        //voxel contents (i.e. organ values)
  6.  
  7.  
  8.  
  9. //LoadFile.cpp
  10. #include<string>
  11. #include<fstream>
  12. #include<iostream>
  13. #include<Variables.h>
  14.  
  15. using namespace std;
  16.  
  17. // Voxel information arrays
  18. double ***g_xyz;
  19. int *g_x;
  20. int *g_y;
  21. int *g_z;
  22.  
  23. //Some other variable declerations
  24. ...
  25.  
  26. void callLoadFile()
  27. {
  28. // Ask user for input file information
  29. cout << endl << "File to be loaded and array size (*.txt X Y Z): ";
  30. cin >> filename >> g_numOfVoxelsX >> g_numOfVoxelsY >> g_numOfVoxelsZ;
  31.  
  32. // Create the voxel 3d array
  33. g_xyz = new double**[g_numOfVoxelsX];
  34. for (i = 0; i<=g_numOfVoxelsX; i++) {
  35.      g_xyz[i] = new double*[g_numOfVoxelsY];
  36.      for (j = 0; j<=g_numOfVoxelsY; j++) {
  37.          g_xyz[i][j] = new double[g_numOfVoxelsZ];
  38.          }
  39.      }
  40.  
  41. //Rest of code
  42. ...
  43. }
  44.  
When I try and create an array of size 300 by 300 by 300, for example, everything works well. If I try anything larger than 475 by 475 by 475 though, my program crashes.

I've attempted to do some debugging by putting in comments. When I try 512 by 512 by 512, the program crashes at the point where it creates the 1 by 512 by 512.

If I run the compiler in debug mode (I'm using Dev-C++) and step past 1 by 512 by 512 and then let the program go, the array will be created with no problem.

I'm pretty new to C++ programming ... I didn't know if it was a problem of not having time to allocate the space, so I added a wait period - to no resolve. Are there inherent limitations in creating arrays of arbitrary size using this method?

Does anybody have any ideas?

Thanks!
-Michael
Feb 14 '07 #1
4 1506
mikejfe
12
I might add that I'm using Windows XP, 1.7GHz Duo, 2GB of memory.

Thanks.
Feb 14 '07 #2
Ganon11
3,652 Expert 2GB
Well, I know that creating 512x512x512 entries is 134,217,728 doubles, which takes up 1,073,741,824 bytes (with an 8 byte sized double) - my computer, right now, has only 2,337,832,960 bytes of storage free, which is more than 2 GB (2.17 approx.). Assuming you have some 'stuff' on your computer, you probably don't have enough free memory to handle this much data.
Feb 14 '07 #3
willakawill
1,646 1GB
I might add that I'm using Windows XP, 1.7GHz Duo, 2GB of memory.

Thanks.
Hi. When you use the new operator in windows you are asking for a contiguous block of free memory just for your app. In this case (512x512x512) you are asking for 1,073,741,824 bytes of contiguous free memory. Aint gonna happen no matter how much memory you have installed.

I have 4Gb and I would normally run foul of windows at around requests for 800mb. Remember, it is not how much memory you have installed. It is how much contiguous (non interupted, in a row) memory windows can get hold of that counts

If you can't get away with using floats instead of doubles, try creating 2 arrays separately and split the load. I have done that with 5 different splits before and got it to work
Feb 14 '07 #4
mikejfe
12
Great. I'll try spliting the load up. Thank you for your help!

-Michael
Feb 14 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: mortoray | last post by:
Throughout the PHP manual, and normal code, one finds this construct: $var = array( ... ); However, as far as I can tell this is quite inefficient, since it always means two arrays are being...
4
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
2
by: Prince of Code | last post by:
Hey Guys Lets assume we have two arrays one bug array - main array another user array - sub array The bug array contains the id of the user to whom the bug is assigned to. This Id is present...
22
by: Vijay | last post by:
With the option strict On set..... Dim fs As FileStream = File.OpenRead(strFile) With fs Dim buffer(fs.Length) As Byte ' <--- Option Strict On disallows implicit conversions from 'Long' to...
4
by: jayharris | last post by:
I'm having a ton of trouble initializing a multi-dimensional array inside a constructor, largely because I don't know the size of the array until runtime. I have a class that looks like this: ...
33
by: Zytan | last post by:
I want to make a zero element array. I know that Nothing is not the same as a zero element array, since I can't get the length of, or iterate through, an array = Nothing. I could make a zero...
5
by: David Golightly | last post by:
Quick question for the gurus out there: in ECMAScript, one can create a new Array object with a length like so: var animals = new Array(128); This creates a new Array object with a "length"...
1
by: 8rea | last post by:
Hello, I want to make a matrix like this: System::Drawing::Drawing2D::Matrix^ L; L=gcnew( System::Drawing::Drawing2D::Matrix::Matrix(rect,plgpts)); System::Drawing::Drawing2D::Matrix^ L;...
14
by: Dan Rumney | last post by:
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = ; as opposed to using a constructor...
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...
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...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.