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

storing data in file instead of memory

I've to store an array of structures:

typedef struct
{
double origin[3];
double e_field_at_origin_real, e_field_at_origin_imag;
double direction[3];
double pathlength;
int depth;
}ray;

A single instance occupies 80 bytes of memory on my machine. I need
to store an array of more than 1,000,000 structures. My program is
failing if the array size exceeds 400,000 because I other big data
structures to store as well. Do you think it will be a better idea to
store the list on a file and use the file as an array ?

Jun 27 '08 #1
7 1903
On Jun 3, 8:57 am, pereges <Brol...@gmail.comwrote:
I've to store an array of structures:

typedef struct
{
double origin[3];
double e_field_at_origin_real, e_field_at_origin_imag;
double direction[3];
double pathlength;
int depth;

}ray;

A single instance occupies 80 bytes of memory on my machine. I need
to store an array of more than 1,000,000 structures. My program is
failing if the array size exceeds 400,000 because I other big data
structures to store as well. Do you think it will be a better idea to
store the list on a file and use the file as an array ?
Depends. You might not need a 1.000.000 elements array in the first
place.
The hard disk is a lot slower than the RAM, but a lot bigger. You can
store all your data there, and have, say 10.000 structures loaded in
memory.
But this is not topical for comp.lang.c; FILE streams may very well be
implemented entirely in memory.
Jun 27 '08 #2
On 3 Jun 2008 at 5:57, pereges wrote:
I've to store an array of structures:

A single instance occupies 80 bytes of memory on my machine. I need
to store an array of more than 1,000,000 structures. My program is
failing if the array size exceeds 400,000 because I other big data
structures to store as well. Do you think it will be a better idea to
store the list on a file and use the file as an array ?
Can't you buy more memory? I mean, most people probably have 80Mb going
spare in their wristwatches nowadays...

Failing that, storing to disk should be an absolute last resort. As long
as there aren't too many writes, it will almost certainly be orders of
magnitude quicker to keep the data in RAM using some compression scheme,
and decompress it on-the-fly as needed.

Jun 27 '08 #3
On 3 Jun, 09:25, Antoninus Twink <nos...@nospam.invalidwrote:
On *3 Jun 2008 at *5:57, pereges wrote:
I've to store an array of structures:
A single instance *occupies 80 bytes of memory on my machine. I need
to store an array of more than 1,000,000 structures. My program is
failing if the array size exceeds 400,000 because I other big data
structures to store as well. Do you think it will be a better idea to
store the list on a file and use the file as an array ?

Can't you buy more memory? I mean, most people probably have 80Mb going
spare in their wristwatches nowadays...

Failing that, storing to disk should be an absolute last resort. As long
as there aren't too many writes, it will almost certainly be orders of
magnitude quicker to keep the data in RAM using some compression scheme,
and decompress it on-the-fly as needed.
what a sensible post!

to the OP: the values in your struct mostly seem to be doubles.

typedef struct
{
double origin[3];
double e_field_at_origin_real, e_field_at_origin_imag;
double direction[3];
double pathlength;
int depth;
}ray;

Do you really use the full range of double for all the values?
Is depth really a 32-bit value (as int is usually 32-bit on modern
hardware. I'm not saying change your struct but consider Twink's idea
of compression and where it might be applied.
--
Nick Keighley

Jun 27 '08 #4
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>A single instance occupies 80 bytes of memory on my machine. I need
to store an array of more than 1,000,000 structures. My program is
failing if the array size exceeds 400,000 because I other big data
structures to store as well. Do you think it will be a better idea to
store the list on a file and use the file as an array ?
>Can't you buy more memory? I mean, most people probably have 80Mb going
spare in their wristwatches nowadays...
He probably already has more memory. The first thing to check is
that he hasn't got some limit set on his memory use that he can
change. That'll be operating-system-specific: in unix with bash
you would use the "ulimit" command. Also note that there may be
separate limits for stack and heap memory.

-- Richard
--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
Jun 27 '08 #5
pereges <Br*****@gmail.comwrote:
I've to store an array of structures:
typedef struct
{
double origin[3];
double e_field_at_origin_real, e_field_at_origin_imag;
double direction[3];
double pathlength;
int depth;
}ray;
A single instance occupies 80 bytes of memory on my machine. I need
to store an array of more than 1,000,000 structures. My program is
failing if the array size exceeds 400,000 because I other big data
structures to store as well. Do you think it will be a better idea to
store the list on a file and use the file as an array ?
It's not clear if you create an array like this

ray all_may_rays[ 1000000 ];

or if you use dynamically allocated memory, e.g. using

ray * all_may_rays;
all_may_rays = malloc( 1000000 * sizeof *all_may_rays );
if ( all_may_rays == NULL ) {
fprintf( stderr, "Not enough memory for rays\n" );
exit( EXIT_FAILURE );
}

If you use the first method then I would consider using dynamically
allocated memory. While the amount of memory available for arrays
as created with the first method can be rather limited, the second
method should only get you in trouble if you need about the same
amount of memory as is available on your machine (and it may even
do some storing on the disk automatically for you on many modern
systems that have swap space).
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jun 27 '08 #6
vi******@gmail.com wrote:
FILE streams may very well be implemented entirely in memory.
How would you be able to access disk files (or named files) with fopen
if this were so? I think C streams need some kind persistent storage.
Maybe I'm not thinking this out though.

Jun 27 '08 #7

"pereges" <Br*****@gmail.comwrote in message
news:76**********************************@f24g2000 prh.googlegroups.com...
I've to store an array of structures:

typedef struct
{
double origin[3];
double e_field_at_origin_real, e_field_at_origin_imag;
double direction[3];
double pathlength;
int depth;
}ray;

A single instance occupies 80 bytes of memory on my machine. I need
to store an array of more than 1,000,000 structures. My program is
failing if the array size exceeds 400,000 because I other big data
structures to store as well. Do you think it will be a better idea to
store the list on a file and use the file as an array ?
I first read this as 80GB. 80MB doesn't sound that much and you're failing
at 32MB anyway; what do all the other tables add up to?

How you thought at all of using float instead of double? That'll pretty much
halve the requirement to 40MB (but will still fail it seems).

Where do the fields origin and direction come from? If they are simply
copies of points in other data structures, you might be able to store
pointers or indices to those points instead (so 24 bytes becomes 4 bytes).

Or possibly the same origin or direction is shared amongst many different
rays; then it may be possible to store one copy only of each xyz value and
again use indices or pointers to it. This will require some analysis.

When some years ago I had to store large numbers of xyz points in memory
(together with transformation data and other stuff), I created a packed (not
compressed) record format. This worked well when a large proportion of
values were 0.0 or 1.0, or had many trailing zero bits. But access is then
much more complex and slower.

It might also be possible (depending on exactly what your appl does), to
partition the task, say into regions. And it could be that you can do a
region at a time and the number of rays for each region is much smaller than
for the entire task.

As for storing the file on disk: your virtual memory system should easily be
able to cope with an extra 80MB or so. If not then you should see what else
is using the memory. Or maybe just install more ram as someone suggested...

--
Bartc
Jun 27 '08 #8

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

Similar topics

3
by: Dave Smithz | last post by:
Hi There, Being quite new to MS-SQL I would like to ask if there is a general opinion of what approach should be taken to storing things like external documents and images in databases. ...
6
by: supercomputer | last post by:
I am using this function to parse data I have stored in an array. This is what the array looks like: , , , , , , , , , , , , , , , , , , , , , , , ] This is the code to parse the array:
19
by: Johnny Google | last post by:
Here is an example of the type of data from a file I will have: Apple,4322,3435,4653,6543,4652 Banana,6934,5423,6753,6531 Carrot,3454,4534,3434,1111,9120,5453 Cheese,4411,5522,6622,6641 The...
1
by: VMI | last post by:
Is it possible to store the data in a datatable in the hard disk instead of the memory? By default, when a datatable's being filled, the table (and data) will remain in memory. Would it be possible...
9
by: Adam J Knight | last post by:
Hi all, Just wondering whats everyones prefered method of storing images ? 1) File System 2) Database (SqlServer) (Seems to be easier, but has a performance hit) Appreciate some insight!!!...
6
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
0
by: mustakbal | last post by:
I was wondering if in VB6, the contents of a decoded file could be stored in memory instead of in a temporary file. I found out that this could be done in VB.Net right "after using DecodeToByte to...
10
by: deciacco | last post by:
I'm writing a command line utility to move some files. I'm dealing with thousands of files and I was wondering if anyone had any suggestions. This is what I have currently: $arrayVirtualFile =...
6
by: Carl Banks | last post by:
I was wondering if anyone had any advice on this. This is not to study graph theory; I'm using the graph to represent a problem domain. The graphs could be arbitrarily large, and could easily...
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: 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...
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
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...

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.