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

dynamic memory for large arrays

Dear All!

I've got a question which is rather system specific case.
Suppose I am dealing with a large array of ~4Gig of entities.
The question is : what is faster , to address it through a binary file
created on disk or using dynamic memory which is extended through a large
swap file (again on disk)? Note that swap file is created at the
point of the disk partition.
I would be grateful if in addition to your comments you could point me to
the relevant source (URL or else).

Thanks,
Akyl.

Nov 14 '05 #1
3 1615
Akyl Tulegenov <pc****@unix.ccc.nottingham.ac.uk> wrote:
I've got a question which is rather system specific case.
Quite. So why post it here? We can't answer your question.
Suppose I am dealing with a large array of ~4Gig of entities.
The question is : what is faster , to address it through a binary file
created on disk or using dynamic memory which is extended through a large
swap file (again on disk)? Note that swap file is created at the
point of the disk partition.
Who knows? Measure, measure, measure. This depends not only on the OS,
the compiler, and the technique used to map the dynamic memory, but
probably also on the relative speeds of the swap disk and the normal FS,
and several others. Measure, and then assume your measurements are
correct for you and nobody else.
I would be grateful if in addition to your comments you could point me to
the relevant source (URL or else).


"The" relevant source? I don't think you quite understand this "system
specific" idea. There must be hundreds of relevant sources. Do a web
search; _you_ know what's inside your system, we don't.

Richard
Nov 14 '05 #2
> I've got a question which is rather system specific case.

You're right, it's off-topic and risks getting flamed because of that.
Suppose I am dealing with a large array of ~4Gig of entities.
The question is : what is faster , to address it through a binary file
created on disk or using dynamic memory which is extended through a large
swap file (again on disk)? Note that swap file is created at the
point of the disk partition.
I would be grateful if in addition to your comments you could point me to


I'd suggest using memory-mapped I/O if you have access to this.
You'll get the best of both worlds.

If you have access to libc/glibc, mmap() is your friend.
Nov 14 '05 #3
Akyl Tulegenov wrote:
Dear All!

I've got a question which is rather system specific case.
Suppose I am dealing with a large array of ~4Gig of entities.
The question is : what is faster , to address it through a binary file
created on disk or using dynamic memory which is extended through a large
swap file (again on disk)? Note that swap file is created at the
point of the disk partition.
I would be grateful if in addition to your comments you could point me to
the relevant source (URL or else).

Thanks,
Akyl.


A great topic for news:comp.programming (follups set).

As other people have stated, measure.

With memory access, you may get a "page fault" which tells
the operating system to swap in memory from a "virtual page".
This would be your worst case timing.

When reading from a file, your worst case is that you
have to read from the file without any caching. Best
case is that the data is in a cache somewhere.

Another alternative is for you to allocate some memory and
read in a chunk of data. You can set the chunk size yourself.

As for references, search the web for:
"Operating Systems" "page fault"
or "double buffering"
or "spooling".

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #4

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

Similar topics

12
by: Tan Thuan Seah | last post by:
Hi all, I was told this in one of the university course I was doing. In C we may expect good performance for: double a, c, d; for (i=0; i<N; i++) for(j=0; j<N; j++) a = a + c *d;
5
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I...
8
by: Chad | last post by:
hello, i am losing memory each time i make this call to a C++ dll (I make frequent calls). 'in VB.Net Declare Function grab Lib "grabber.dll" _ (ByRef lpBuf As Byte, ByVal lnum As Integer)...
14
by: romayankin | last post by:
Hello All, I'm writing cross-platform code so i'm bound to standards. Here is the code I have: ~~~~~~~~~~~~~~~~~~ double **mx = new double*; for(int i = 0; i < col - 1; i++) { mx = new...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
14
by: vivek | last post by:
i have some doubts on dynamic memory allocation and stacks and heaps where is the dynamic memory allocation used? in function calls there are some counters like "i" in the below function. Is...
4
by: Atemporal | last post by:
hi, all, i got some problem when define and use large dynamic two dimension arrays. At first, i use vector<vector<double>p1, i have three such arrays and each is around 10000*10000, the program...
10
by: swornavidhya.mahadevan | last post by:
Which allocation (Static / Dynamic) is suitable for the situation when we are trying to allocate for a overloaded memory when the memory is full and no space to allocate. What will happen if both...
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: 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: 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
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
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.