Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 11th, 2006, 09:05 AM
Marcel
Guest
 
Posts: n/a
Default What is used for storage

Hello all,

I am a C++ beginner.

I would like to know where and how a C++ application stores it's data.

For example, imagine an application to manage your DVD collection. DVD can
be enterd into it by typing a name, duration, description. What is most
common, best practice: to store the DVD's entrys in a flatfile, in a
database (what database) or is there another solution.

I can imagine that maybe for not much data a flatfile is the best solution
but as the DVD collection will grow over time maybe a database is a better
solution?

Marcel


  #2  
Old January 11th, 2006, 11:15 AM
Ben Pope
Guest
 
Posts: n/a
Default Re: What is used for storage

Marcel wrote:[color=blue]
> Hello all,
>
> I am a C++ beginner.
>
> I would like to know where and how a C++ application stores it's data.[/color]

Where you tell it to.
[color=blue]
> For example, imagine an application to manage your DVD collection. DVD can
> be enterd into it by typing a name, duration, description. What is most
> common, best practice: to store the DVD's entrys in a flatfile, in a
> database (what database) or is there another solution.[/color]

Well, RAM, initially, and then if you need it to persist, then a file
and a database or probably two most common options.
[color=blue]
> I can imagine that maybe for not much data a flatfile is the best solution
> but as the DVD collection will grow over time maybe a database is a better
> solution?[/color]

Correct.

For now, I suggest you use a file. When performance becomes a problem,
work out another solution.

If you abstract the reading and writing behind an interface, then you
should be able to change the implementation from a file to a database
without changing too much code.

#include <vector>
#include <string>

class myData {};

// Pure abstract Interface
class serialiser {
public:
virtual ~serialiser() = 0 {}

virtual std::vector<myData> read() = 0 {}
virtual bool write(const std::vector<myData>& vec) = 0 {}
};

class file : public serialiser {
public:
file(std::string& filename) {/*open file*/}
~file() {/*close file*/}
std::vector<myData> read() { return std::vector<myData>(); }
bool write(const std::vector<myData>& vec) { return false; }
};
class database : public serialiser {};

int main() {
std::string filename("filename");
std::auto_ptr<serialiser> dataStore(new file(filename));
std::vector<myData> data = dataStore->read();
}

That should give you the basic idea, obviously all the difficult bits
are missing.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
  #3  
Old January 11th, 2006, 11:25 AM
Stephan Brönnimann
Guest
 
Posts: n/a
Default Re: What is used for storage

As you are a C++ beginner you should go for flat files first.
The disadvantage is that it can be accessed from the local machine only
(unless you're using shared file systems (NFS, Samba, ...)).
The design should encapsulate the I/O of an entry in the collection:
define the necessary interface in an abstract base class and provide
a concrete implementation that works with flat files.

Later you can expand your design by the strategy pattern and provide
an I/O interface to a database.

Regards, Stephan

  #4  
Old January 11th, 2006, 11:35 AM
Marcel
Guest
 
Posts: n/a
Default Re: What is used for storage


"Marcel" <sorryafraidofspam@nospam.com> schreef in bericht
news:fc86$43c4d4cd$d969db07$24324@cache40.multikab el.net...[color=blue]
> Hello all,
>
> I am a C++ beginner.
>
> I would like to know where and how a C++ application stores it's data.
>
> For example, imagine an application to manage your DVD collection. DVD can
> be enterd into it by typing a name, duration, description. What is most
> common, best practice: to store the DVD's entrys in a flatfile, in a
> database (what database) or is there another solution.
>
> I can imagine that maybe for not much data a flatfile is the best solution
> but as the DVD collection will grow over time maybe a database is a better
> solution?
>
> Marcel
>[/color]

Ok thanks for your advice friends!

Marcel


  #5  
Old January 11th, 2006, 05:45 PM
JustBoo
Guest
 
Posts: n/a
Default Re: What is used for storage

On Wed, 11 Jan 2006 12:21:22 +0100, "Marcel"
<sorryafraidofspam@nospam.com> wrote:[color=blue]
>
>Ok thanks for your advice friends![/color]

Three small posts in an ocean of indifference.

Need I say more? No, no more. I will try to do my part as well.

[In a quiet humble voice]
"No crime is so great as daring to excel."
- Winston Churchill
  #6  
Old January 11th, 2006, 06:05 PM
Howard
Guest
 
Posts: n/a
Default Re: What is used for storage


"JustBoo" <JustBoo@BooWho.com> wrote in message
news:tpfas1tpj4jpsh9nmr952uveo5hi1hdlnj@4ax.com...[color=blue]
> On Wed, 11 Jan 2006 12:21:22 +0100, "Marcel"
> <sorryafraidofspam@nospam.com> wrote:[color=green]
>>
>>Ok thanks for your advice friends![/color]
>
> Three small posts in an ocean of indifference.
>
> Need I say more? No, no more. I will try to do my part as well.
>
> [In a quiet humble voice]
> "No crime is so great as daring to excel."
> - Winston Churchill[/color]

What????? Perhaps you wanted alt.poetry?

-Howard


  #7  
Old January 11th, 2006, 06:15 PM
Default User
Guest
 
Posts: n/a
Default Re: What is used for storage

Ben Pope wrote:
[color=blue]
> Marcel wrote:[color=green]
> > Hello all,
> >
> > I am a C++ beginner.
> >
> > I would like to know where and how a C++ application stores it's
> > data.[/color]
>
> Where you tell it to.
>[color=green]
> > For example, imagine an application to manage your DVD collection.
> > DVD can be enterd into it by typing a name, duration, description.
> > What is most common, best practice: to store the DVD's entrys in a
> > flatfile, in a database (what database) or is there another
> > solution.[/color]
>
> Well, RAM, initially, and then if you need it to persist, then a file
> and a database or probably two most common options.
>[color=green]
> > I can imagine that maybe for not much data a flatfile is the best
> > solution but as the DVD collection will grow over time maybe a
> > database is a better solution?[/color]
>
> Correct.[/color]


Depends. The size doesn't matter all that much, especially with modern
computers. You can rip through even a sizeable flatfile in short order.
It's really more of how you're using the data. If there are going to be
lots of complicated searches and such, then a relational database will
become important. Naturally, proper design of the tables becomes vital
at that point, but that's well outside the scope of this newsgroup.



Brian
  #8  
Old January 11th, 2006, 06:35 PM
JustBoo
Guest
 
Posts: n/a
Default Re: What is used for storage

On Wed, 11 Jan 2006 17:49:32 GMT, "Howard" <alicebt@hotmail.com>
wrote:[color=blue]
>"JustBoo" <JustBoo@BooWho.com> wrote in message
>news:tpfas1tpj4jpsh9nmr952uveo5hi1hdlnj@4ax.com.. .[color=green]
>> On Wed, 11 Jan 2006 12:21:22 +0100, "Marcel"
>> <sorryafraidofspam@nospam.com> wrote:
>> [In a quiet humble voice]
>> "No crime is so great as daring to excel."
>> - Winston Churchill[/color]
>
>What????? Perhaps you wanted alt.poetry?
>-Howard[/color]

Don't quit your day job Howie. If you have one....

Men occasionally stumble over the truth, but most
of them pick themselves up and hurry off as if
nothing had happened. - Winston Churchill
  #9  
Old January 11th, 2006, 06:55 PM
red floyd
Guest
 
Posts: n/a
Default Re: What is used for storage

JustBoo wrote:[color=blue]
> [insult redacted][/color]

*PLONK*
  #10  
Old January 11th, 2006, 07:45 PM
Howard
Guest
 
Posts: n/a
Default Re: What is used for storage


"JustBoo" <JustBoo@BooWho.com> wrote in message
news:rfjas1hl93u5qc3lg46l5a1uch4aj2du8a@4ax.com...[color=blue]
> On Wed, 11 Jan 2006 17:49:32 GMT, "Howard" <alicebt@hotmail.com>
> wrote:[color=green]
>>"JustBoo" <JustBoo@BooWho.com> wrote in message
>>news:tpfas1tpj4jpsh9nmr952uveo5hi1hdlnj@4ax.com. ..[color=darkred]
>>> On Wed, 11 Jan 2006 12:21:22 +0100, "Marcel"
>>> <sorryafraidofspam@nospam.com> wrote:
>>> [In a quiet humble voice]
>>> "No crime is so great as daring to excel."
>>> - Winston Churchill[/color]
>>
>>What????? Perhaps you wanted alt.poetry?
>>-Howard[/color]
>
> Don't quit your day job Howie. If you have one....
>
> Men occasionally stumble over the truth, but most
> of them pick themselves up and hurry off as if
> nothing had happened. - Winston Churchill[/color]

Ooh, it called me "Howie"! A touch, I do confess it! I fear I breathe my
last. Oh woe...

*plonk*








  #11  
Old January 11th, 2006, 08:56 PM
JustBoo
Guest
 
Posts: n/a
Default Re: What is used for storage

On Wed, 11 Jan 2006 19:32:14 GMT, "Howard" <alicebt@hotmail.com>
wrote:[color=blue]
>"JustBoo" <JustBoo@BooWho.com> wrote in message
>news:rfjas1hl93u5qc3lg46l5a1uch4aj2du8a@4ax.com.. .[color=green]
>> On Wed, 11 Jan 2006 17:49:32 GMT, "Howard" <alicebt@hotmail.com>
>> wrote:[/color]
>Ooh, it called me "Howie"! A touch, I do confess it! I fear I breathe my
>last. Oh woe...[/color]

Yeesh, like I said, don't quit your day job. And if this is what the
witless sheep call "Sarcasm...." Man, I mean, what would an actual
joke look like to the gray robots. A nut with a screw in it?

"The dullness of the fool is the whetstone of the wits." Indeed.

They fall in line in such a predictable manner. Almost as if
scripted... mmm.
[color=blue]
>*plonk*[/color]

Wow, a sheep with two heads! What a concept. I wonder if sheep, two
heads or one, realize they get what they give... Nah! Don't be silly,
that would require actual thought and not just repetitive Pavlovian
braying.

"There is real magic in enthusiasm. It spells the difference between
mediocrity and accomplishment." - Norman Vincent Peale

Gray Sheep never understand that.
  #12  
Old January 12th, 2006, 02:35 PM
Marcel
Guest
 
Posts: n/a
Default Re: What is used for storage

[color=blue][color=green]
>>
>> Correct.[/color]
>
>
> Depends. The size doesn't matter all that much, especially with modern
> computers. You can rip through even a sizeable flatfile in short order.
> It's really more of how you're using the data. If there are going to be
> lots of complicated searches and such, then a relational database will
> become important. Naturally, proper design of the tables becomes vital
> at that point, but that's well outside the scope of this newsgroup.
>
>[/color]
Thanks for your help Brian,

I have a www/PHP background and i was learned that I/O on plaintext files is
potentially slow. But maybe i have to turn the switch in my head because now
we are talking about C++ applications.....

Regards,

Marcel


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles