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 and Retrieving a large amount of data

Hi Friends,

I have to store large amount of data and retrieve the same data then write into file in C++.
Currently I am using vector to store and retrieve. But vector is taking more time to store and retrieve the element. Is any other best data structure to store and retrieve large amount of data in unordered way?
Please suggest me the best solution to reduce the time.

Example code:
Expand|Select|Wrap|Line Numbers
  1. int I1 = 700,I2 = 32, I3 = 16;
  2. //declare and resize the vector size
  3. vector< vector < vector < vector<DOUBLE> > > > vPARAM; 
  4. vPARAM.resize(I1, vector< vector < vector<DOUBLE> > >
  5. (I2, vector< vector<DOUBLE> > (I3, vector<DOUBLE> (0))));
  6.  
  7. //Insert
  8. //In the Loop
  9. //The final index "value" it will go unlimited
  10. //I1,I2,I3 also, i will store randomly...
  11. //For eg,First time i will store 100the element,then 50th....
  12. vPARAM.at(I1).at(I2).at(I3).push_back(value);
  13.  
  14. //Retrieve
  15. //In the Loop
  16. for(lines =0; lines < vecPARAMETER.size();lines++)
  17. iValue = vecPARAMETER[I1][I2][I3][lines];
  18. fwrite(&iValue,8,1,fp);

Thanks,
Jothi
Nov 28 '12 #1
3 5268
weaknessforcats
9,208 Expert Mod 8TB
If the data is not ordered, then why are you using a three-dimensional vector?

You have doubles, say 1000000 of them, then why not:

Expand|Select|Wrap|Line Numbers
  1. double* data = new double[1000000];
  2. read ( data, sizeof(double), 1000000 *sizeof(double), fp); 
If you don't have a binary file then read the array record by record. Each record can be read into a calculated location in the array. There is never any need to fill dimensions individually.

Please note that there are no 3d arrays in C++. There are only one-dmensional arrays. Read this: http://bytes.com/topic/c/insights/77...rrays-revealed
Nov 28 '12 #2
Hi,

Thanks for your response.
What I am trying to say is, the data storing in vector is not sequential. I will access any index in the vector at any time.
In between some element can be blank also. Though my vector size is more, I will store the data some index only, some index can be blank. So i cant read and write directly like double[100000]. When I am storing data in all the index, that time we can use this concept. I am in different scenario, that's why i am asking which is best data structure to store and retrieve data with less time complexity?? But I need 4 dimensional to store and retrieve data..
Nov 29 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
Vectors expand as you add elements and I susect this expansion is what is consuming ever larger amounts of time.

You might try creating a vector of the right size by using the reserve() method. Then I would initialize every element of the vector with a value that you conider "empty". Now you should be able to hop around any of the elements with no increase in time, ever.

Possibly you could use a struct:

Expand|Select|Wrap|Line Numbers
  1. struct Data
  2. {
  3.    double value;
  4.    bool   state;
  5. };
Here you have a vector<Data> where you can use the state memer to denote "empty" or not.
Nov 29 '12 #4

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

Similar topics

1
by: Ice Man | last post by:
Hi All, I will need to send bewteen 2 asp pages very large amounts of data what is the best way to send it and to read it? for ex. I know this method: For i = 1 To Request.QueryString.Count...
2
by: steve | last post by:
Hi, I have researched but have not found a good solution to this problem. I am importing large amounts of data (over 50 Meg) into a new mysql db that I set up. I use >mysql dbname <...
5
by: Mike | last post by:
This is a general question on the best way to import a large amount of data to a MS-SQL DB. I can have the data in just about any format I need to, I just don't know how to import the data. I...
1
by: Bart | last post by:
Dear all, I would like to encrypt a large amount of data by using public/private keys, but I read on MSDN: "Symmetric encryption is performed on streams and is therefore useful to encrypt large...
4
by: loretta | last post by:
I have data within an xml tag that is being truncated when being read into a javascript variable. On Firefox, I am only getting up to 4096 characters. On IE, I am getting 31324 characters. I can...
4
by: eggie5 | last post by:
OK, so I'm trying to get a large amount of text back to my ASP script on the server. My large amount of text is the source to a web page, and I want to preserve the formatting on it, ie the...
2
by: Pja | last post by:
hi.. i need some help here.. how do i display large amount of data in vb6.0 in a table form that can be scrolled and to include print functions.. i am using vb6.0 as my front end and ms sql server...
16
by: Jack | last post by:
I need to process large amount of data. The data structure fits well in a dictionary but the amount is large - close to or more than the size of physical memory. I wonder what will happen if I try...
3
by: AnishAbs | last post by:
Hi , I have got a senario in which large amount of data should be copied from MS excel to MS SQL server. which is the best option to do so. Because when I use recordsets the process is very slow and...
3
by: Ale | last post by:
Hi all, how can I execute a large amount of DDL Queries on Access 2000? I've a DDl/SQL Script file which defines a data structure with CREATE TABLE, ALTER TABLE UPDATE TABLE, etc. etc. I know...
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: 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
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...

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.