vectors

J

jagguy

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.
 
I

Ian Collins

jagguy said:
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.
 
V

Victor Bazarov

jagguy said:
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
 
P

puzzlecracker

jagguy said:
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.
 
I

Ian Collins

Phlip said:
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...
 
J

jagguy

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.
 
B

benben

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
 
R

Rolf Magnus

jagguy said:
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.
 
E

Earl Purple

jagguy said:
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.
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Phlip said:
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.
 
P

Phlip

jagguy said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top