473,387 Members | 1,464 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.

storing 1,000,000 records

do you think it will be better to use a file over here instead of a
link list or array ? Can the file be organized as an array so that one
can index into it ?
Apr 6 '08 #1
14 1654
lector wrote:
do you think it will be better to use a file over here instead of a
link list or array ?
If you have enough RAM use it since it is thousands of times faster
than a disk.
Can the file be organized as an array so that one
can index into it ?
Yes.

If record size (on disk) is X, the 5876th record is at offset
X*5875 bytes.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Apr 6 '08 #2
On Apr 7, 12:32 am, jacob navia <ja...@nospam.comwrote:
>
Yes.

If record size (on disk) is X, the 5876th record is at offset
X*5875 bytes.
Can you please tell me what file function specifically does this ?
Apr 6 '08 #3
Is it this function

int fseek ( FILE * stream, long int offset, int origin );

I don't know if it sufficient to have offset as a long int.
Apr 6 '08 #4
lector wrote:
On Apr 7, 12:32 am, jacob navia <ja...@nospam.comwrote:
>Yes.

If record size (on disk) is X, the 5876th record is at offset
X*5875 bytes.

Can you please tell me what file function specifically does this ?
fseek

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Apr 6 '08 #5
"lector" wote:

do you think it will be better to use a file over here instead of a
link list or array ?
No way to tell with the little you have said. About the same as saying :
"Is a car better than a truck?"
>Can the file be organized as an array so that one
can index into it ?
Yes. Here is a link that might be helpful.

http://en.wikipedia.org/wiki/Hash_table
Apr 6 '08 #6
lector wrote:
Is it this function

int fseek ( FILE * stream, long int offset, int origin );
yes
I don't know if it sufficient to have offset as a long int.
if your file is smaller than 2GB yes, I am supposing 32 bit
system.

Since 2GB is 2147483648, you can store 1 millio of records
of up to 2147 bytes, what is not that bad actually.

If not, just use a compiler/OS that provides 64 bit access.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Apr 6 '08 #7
jacob navia wrote:
lector wrote:
>do you think it will be better to use a file over here instead
of a link list or array ?

If you have enough RAM use it since it is thousands of times
faster than a disk.
If you have a suitable OS it will buffer the file, and the
performance difference from an internal buffer will be negligible.
It will also probably be smart enough not to buffer portions of the
file that you do not use.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com

Apr 7 '08 #8
CBFalconer wrote:
jacob navia wrote:
>lector wrote:
>>do you think it will be better to use a file over here instead
of a link list or array ?
If you have enough RAM use it since it is thousands of times
faster than a disk.

If you have a suitable OS it will buffer the file, and the
performance difference from an internal buffer will be negligible.
It will also probably be smart enough not to buffer portions of the
file that you do not use.
Ahh. Yes of course.

So, that OS will not access the disk when you write
1 million records in a file?

Perfect.

Just tell me then one example of a suitable OS...
In any case you are just *confirming* what I said:

Ram is much faster than disk. Only that you rely on the
OS to do that. I recommended not relying on the OS and
do it yourself.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Apr 7 '08 #9
On 6 Apr, 20:27, lector <hannibal.lecto...@gmail.comwrote:
do you think it will be better to use a file over here instead of a
link list or array ? Can the file be organized as an array so that one
can index into it ?
consider using a database

--
Nick Keighley
Apr 7 '08 #10
On Apr 6, 12:27*pm, lector <hannibal.lecto...@gmail.comwrote:
do you think it will be better to use a file over here instead of a
link list or array ? Can the file be organized as an array so that one
can index into it ?
I guess that you will find the easiest success if you use a database.
Apr 7 '08 #11
Do you think it will make things even more efficient if I read and
write data in binary and in chunks of bytes ? I'm doing this using
fread and fwrite functions. eg. something like below

/*-------------------- WRITES EMPLOYEE RECORDS TO A BINARY
FILE-----------------------*/
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *fp;
char another = 'Y';
typedef struct emp_struct
{
char name[40];
int age;
float bs;
} emp;

emp e;

fp = fopen("EMP.DAT", "wb");

if(fp == NULL)
{
puts("Cannot open file");
exit(EXIT_FAILURE);
}
while(another == 'Y')
{
printf("\nEnter name, age and basic salary\n");
scanf("%s %d %f", e.name, &e.age, &e.bs);
fwrite(&e, sizeof(e), 1, fp);

printf("Add another record (Y/N)");
fflush(stdin);
another = getchar();
}

fclose(fp);
return 0;
}
Apr 8 '08 #12
On Apr 7, 10:25*pm, lector <hannibal.lecto...@gmail.comwrote:
Do you think it will make things even more efficient if I read and
write data in binary and in chunks of bytes ? I'm doing this using
fread and fwrite functions. eg. something like below

/*-------------------- WRITES EMPLOYEE RECORDS TO A BINARY
FILE-----------------------*/
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
* * * * FILE *fp;
* * * * char another = 'Y';
* * * * typedef struct emp_struct
* * * * {
* * * * * * * * *char name[40];
* * * * * * * * *int age;
* * * * * * * * *float bs;
* * * * *} emp;

* * * * emp e;

* * * * fp = fopen("EMP.DAT", "wb");

* * * * if(fp == NULL)
* * {
* * * * * * * * puts("Cannot open file");
* * * * * * * * exit(EXIT_FAILURE);
* * * }
* * * * while(another == 'Y')
* * {
* * * * * * * * printf("\nEnter name, age and basic salary\n");
* * * * * * * * scanf("%s %d %f", e.name, &e.age, &e.bs);
* * * * * * * * fwrite(&e, sizeof(e), 1, fp);

* * * * * * * * printf("Add another record (Y/N)");
* * * * * * * * fflush(stdin);
* * * * * * * * another = getchar();
* * * }

* * * * fclose(fp);
* * * *return 0;

}
Yes, binary is faster though not portable.

Even better would be a system that allows you to create hashed or B-
tree indexes on your table.

And can you imagine how nice it would be to have arbitrary search
features that can find things like "name BETWEEN 'Johnson' AND
'Johnson'" or "bs 29575.00".

Let's let our imagination run wild and suppose that we could even do
things like collecting average age or sum of basic salary.

I guess we're just dreaming now. Too bad there is nothing like that
on the planet.
;-)
Apr 8 '08 #13
On Apr 8, 10:41 am, user923005 <dcor...@connx.comwrote:
On Apr 7, 10:25 pm, lector <hannibal.lecto...@gmail.comwrote:
Yes, binary is faster though not portable.

Even better would be a system that allows you to create hashed or B-
tree indexes on your table.

And can you imagine how nice it would be to have arbitrary search
features that can find things like "name BETWEEN 'Johnson' AND
'Johnson'" or "bs 29575.00".

Let's let our imagination run wild and suppose that we could even do
things like collecting average age or sum of basic salary.

I guess we're just dreaming now. Too bad there is nothing like that
on the planet.
;-)
Yes, but then there might be an issue with choosing a hash function
Apr 8 '08 #14
On Mon, 7 Apr 2008 22:25:18 -0700 (PDT), lector
<ha***************@gmail.comwrote:
>Do you think it will make things even more efficient if I read and
write data in binary and in chunks of bytes ? I'm doing this using
fread and fwrite functions. eg. something like below
Writing one large chunk as opposed to several small chunks usually
means less calls to the I/O functions which usually means less
overhead for those calls. This has nothing to do with binary vs text.
If you built a large string containing the text equivalent of your
structure members, you would achieve the same efficiency with regard
to calling I/O functions without the problems introduced by binary
noted below.
>
/*-------------------- WRITES EMPLOYEE RECORDS TO A BINARY
FILE-----------------------*/
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *fp;
char another = 'Y';
typedef struct emp_struct
{
char name[40];
int age;
float bs;
} emp;

emp e;

fp = fopen("EMP.DAT", "wb");

if(fp == NULL)
{
puts("Cannot open file");
exit(EXIT_FAILURE);
}
while(another == 'Y')
{
printf("\nEnter name, age and basic salary\n");
scanf("%s %d %f", e.name, &e.age, &e.bs);
This opens up the possibility of the user entering more than 39
characters into name. This will not support a name which contains an
embedded blank. You really should check that scanf returns 3.
> fwrite(&e, sizeof(e), 1, fp);
If you change compilers, or possibly even compiler options, the file
may be difficult to process because of different padding in the
structure. If you transport the file to a different system, the int
and the float may have problems due to endian-ness or representation.
>
printf("Add another record (Y/N)");
fflush(stdin);
fflush is not defined for input streams.
> another = getchar();
What will you do if the user enters 'y'?

On most interactive systems, the user will need to press Enter after
typing the 'Y'. This will leave a '\n' in the buffer. When you go
back to the scanf, this character will be processed immediately and
the user will never be able to enter the three values.
}

fclose(fp);
return 0;
}

Remove del for email
Apr 8 '08 #15

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

Similar topics

4
by: jeff brubaker | last post by:
Hello, Currently we have a database, and it is our desire for it to be able to store millions of records. The data in the table can be divided up by client, and it stores nothing but about 7...
3
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around...
6
by: Kieran Benton | last post by:
Hi, I have quite a lot of metadata in a WinForms app that I'm currently storing within a hashtable, which is fine as long as I know the unique ID of the track (Im storing info on media files). Up...
9
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1....
2
by: hendry.johan | last post by:
Hi, I'm currently developing an HR system which involves storing a lot of configurations per module, such as payroll module, absence/shift module, training module, etc. total: around 100...
3
by: ArmsTom | last post by:
I was using structures to store information read from a file. That was working fine for me, but then I read that anything stored in a structure is added to the stack and not the heap. So, I made...
6
by: arunbalait | last post by:
Hi all. I want to store about 300 crore records into sql server. Is it possible? Whats the actual memory capacity of sql server for storing records..? How many max amount of records can...
1
by: webcm123 | last post by:
I'm looking for a good method of securing ratings. Cookies lock isn't sufficient. In addition to cookies I would need something else. I'm introducing some ways. -= Storing rates inside seperate...
6
by: Lint Radley | last post by:
Hi Everyone, I need an opinion here on storing data for a program I am working on the processes DICOM images. Essentially, my program stores 25-45 (it varies depending on the user) ranges of...
4
by: RobertTheProgrammer | last post by:
Hi folks, Although I'm an experienced programmer, I'm new to ASP and relatively new to web programming, so I hope you'll be patient with my questions. I'm working on a project using ASP.NET and...
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
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?
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
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,...

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.