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

vectors

Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would we
need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.
May 11 '06 #1
11 1577
jagguy wrote:
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would we
need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.

Most applications neither want nor require a database.

--
Ian Collins.
May 11 '06 #2
jagguy wrote:
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Get yourself a copy of "Effective STL" by Meyers. Also, "C++ Standard
Library" by Josuttis is extremely useful.
Since we now have database programs to connect to in the code, why
would we need this extra storage a database couldn't handle?
I don't think I understand the question. RAM versus some remote DB?
Maybe you could use a container to store results from database fields
eg some temperary calculation of 2 fields done over again.


Databases could be a bit slow. Storage local to the process is often
preferred when performance is important.

V
--
Please remove capital As from my address when replying by mail
May 11 '06 #3

jagguy wrote:
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would we
need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.


You must be a really newbie to Computer Science:
a. Do you know what a Database is?
b. Difference between memory and storage?
c. vectors?

learn above: take cs/math/engineering courses, invest time, energy,
meditate, get better, get helped....learn to ask good question, learn
to filter bad questions/answers, be human.

May 11 '06 #4
Ian Collins wrote:
jagguy wrote:
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would
we
need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.

Most applications neither want nor require a database.


Can't you think of a situation where a program needs both a DB and a vector?

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 11 '06 #5
Phlip wrote:
Ian Collins wrote:
jagguy wrote:
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would
we
need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.


Most applications neither want nor require a database.

Can't you think of a situation where a program needs both a DB and a vector?

Just about all of the CGI stuff I'm working on at the moment...

--
Ian Collins.
May 11 '06 #6
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would
we need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.

thanks for some of the tips.
A database is a container and most of the time rarely suffers huge
performance losses compared to reading all the data in some temperary
storage, manipulating it then writing back. A big database like the ones in
SAP don't require C++.
So the need to use a vector appear much less with databases around, so
that's why I ask .
If we know the database size to begin with and we want temperary storage
then an array will do full of object pointers if need be.

I just haven't seen anyone claim we just use a vector for database like
applications then write back to a file when finished with it all , as I have
asked around and it isn't a common problem by the looks of it.

May 11 '06 #7
jagguy wrote:
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would
we need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.

thanks for some of the tips.
A database is a container and most of the time rarely suffers huge
performance losses compared to reading all the data in some temperary
storage, manipulating it then writing back.


Actually, I'd expext a database to be much much slower than a vector. The
advantage is that it can handle huge amounts of data without a significant
slowdown and that it stores its data persistantly.
If we know the database size to begin with and we want temperary storage
then an array will do full of object pointers if need be.
And if we don't know the size at compile-time?
I just haven't seen anyone claim we just use a vector for database like
applications then write back to a file when finished with it all , as I
have asked around and it isn't a common problem by the looks of it.


Well, if you need a database, use a database. A vector is something
different that has other uses. If your question was "why use a vector for
the tasks of a database if we have a database", then the answer would be
that there is no reason.

May 11 '06 #8
> thanks for some of the tips.
A database is a container and most of the time rarely suffers huge
performance losses compared to reading all the data in some temperary
storage, manipulating it then writing back. A big database like the ones in
SAP don't require C++.
So the need to use a vector appear much less with databases around, so
that's why I ask .
If we know the database size to begin with and we want temperary storage
then an array will do full of object pointers if need be.

I just haven't seen anyone claim we just use a vector for database like
applications then write back to a file when finished with it all , as I have
asked around and it isn't a common problem by the looks of it.


Take it this way: with database as ideal as you just described why
bother using variables? Just store all the variables in databases.

A vector is an array. We want array because we can refer to a portion of
the memory with an index.

Regards,
Ben
May 11 '06 #9

jagguy wrote:
thanks for some of the tips.
A database is a container
Not really. A database is primarily a form of persistant storage. A
database will also come with methods to persist and to retrieve data,
which may include some "stored procedures", generally based on how the
database is going to store/retrieve compared to what it
receives/returns.
and most of the time rarely suffers huge
performance losses compared to reading all the data in some temperary
storage, manipulating it then writing back.
Temporary storage? How much data are we talking about?
A big database like the ones in SAP don't require C++.
Nothing "requires" C++. There are other programming languages. Many
databases come with a proprietary language usually based around SQL, eg
Transact and PL/SQL.
So the need to use a vector appear much less with databases around, so
that's why I ask .
vector is used for storage of sequences of data in memory in contiguous
storage. It is used for manipulating the data.

If your project is large scale where the database is used as a form of
persistent storage, and business logic is calculated with a C++ engine,
and possibly there is a client/server architecture whereby you are
writing middleware in C++ that is a client to the database and a server
to other clients, then it is just possible that your code will contain
some sort of logic which involves vectors.
If we know the database size to begin with and we want temperary storage
then an array will do full of object pointers if need be.

I just haven't seen anyone claim we just use a vector for database like
applications then write back to a file when finished with it all , as I have
asked around and it isn't a common problem by the looks of it.


If the database interaction requires you to pass a pointer to
contiguous data of a variable size then you will probably want to use
vector and pass the address of its first element. Your program will
then be able to manipulate your data to the required size without
having to worry about memory management issues.

May 11 '06 #10
Phlip wrote:
Can't you think of a situation where a program needs both a DB and a
vector?


You never need a DB nor a vector, together or not. You can always do all
type of things with a tape in a Turing Machine.

--
Salu2

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
May 11 '06 #11
jagguy wrote:
Could someone please tell me a use for vectors in C++. I know they are
popular today but I am struggling to come up for a use.
Since we now have database programs to connect to in the code, why would
we need this extra storage a database couldn't handle?
Maybe you could use a container to store results from database fields eg
some temperary calculation of 2 fields done over again.


A database record cannot (should not?) contain behavior. It shouldn't have
methods.

Programs very frequently need a list of things-with-behaviors. Maybe a list
of objects of a derived type. Some override a method to do one thing, and
some override it to do another. The calling code would call one method, by
name, and get different behaviors. This decouples the differences in
behavior from the calling code. The calling code doesn't need to say 'if' to
detect which type it has, then do different behavior for each type.

Such a system is easy to extend without changing the calling code. You add a
new type, change its behavior. and add it to the list.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 11 '06 #12

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

Similar topics

10
by: Michael Aramini | last post by:
I need to represent 1D and 2D arrays of numeric or bool types in a C++ program. The sizes of the arrays in my intended application are dynamic in the sense that they are not known at compile time,...
5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
5
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
19
by: chris | last post by:
Hello, I've recently been trying to understand the various structures supplied by c++, and the one I find most confusing is deque. One quick question about this. It seems most implementations...
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
4
by: Dr. J.K. Becker | last post by:
Hi all, I have vectors that holds pointers to other vectors, like so: vector<whatever> x; vector<whatever*> z; z=&x; Now I add something to x
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
2
by: wuzertheloser | last post by:
Use the program skeleton below (starting with #include <stdio.h>) as the starting point for quiz4. Add the necessary code to the functions prob1() and prob2(), and add the other 2 functions, as...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
2
by: joeme | last post by:
How would one using STL do the following tasks: 1) merge 2 sorted vectors with dupes, result shall be sorted 2) merge 2 sorted vectors without dupes, result shall be sorted 3) merge 2...
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: 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:
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: 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,...

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.