Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

persistant data storage

Posted on 2003-11-21
11
Medium Priority
?
307 Views
Last Modified: 2010-04-02
My program needs a database of some kind to store data that I want to keep between sessions.  Something like SQL would be a bit of an overkill I think, as I wont be storing much more than 100-200 records.  Is there any sort of classes out there I could use to store my data in a file, or do I need to make my own?
0
Comment
Question by:lwinkenb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9801522
Whyt about www.mysql.org? You still need to write the whole serializing code that does the job on your side, but that's inevitable.
0
 
LVL 30

Expert Comment

by:Axter
ID: 9801716
It would not be that hard to make your own.

I recomend you use a std::vector or std::map container to store the data at run time, and save it to a file when your program exits.

Do you need to share the data between multiple running threads or executables?

If so, what is your OS?
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 9801717
hmm, If I used mysql, would I have to have the users of my application download and set up a mysql database server?

I'm looking for something that I can use to just store my data in a flat file.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 30

Expert Comment

by:Axter
ID: 9801727
FYI:
If you're target is windows, and your data is simple, you can use the INI API functions.
GetProfileString
WriteProfileString

GetPrivateProfileString
WritePrivateProfileString
GetPrivateProfileInt

I've used these before for storing simple data.
You can use a key name that has a number at the end so that you can pull or write the data.
0
 
LVL 15

Expert Comment

by:efn
ID: 9801734
I thought Metakit looked good for this kind of thing.  I haven't used it myself, though.

http://www.equi4.com/mkoverview.html

--efn
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 9801748
Hey Axter, writing to the registry wont work, because I need to store a bit too much data for that.

eft >> I will give metakit a look
0
 
LVL 30

Expert Comment

by:Axter
ID: 9801753
>>Hey Axter, writing to the registry wont work, because I need to store a bit too much data for that.
How much is too much?
0
 
LVL 30

Accepted Solution

by:
Axter earned 2000 total points
ID: 9801771
Here's a simple example:

class foo
{
public:
      char Name[32];
      int Age;
};

int main(int argc, char* argv[])
{
      foo foo_list[] = {{"Axter", 40},{"jkr", 88},{"lwinkenb", 26},{"efn", 12}};
      int i;
      char Key[99];
      char DataInt[22];
      const char KeyPrefix[] = "Key";
      const char FileNameHoldingData[] = "myfiledata.ini";
      for (i = 0;i < sizeof(foo_list)/sizeof(foo);++i)
      {
            sprintf(Key, "%s_Name%i", KeyPrefix, i);
            WritePrivateProfileString("DataSection", Key, foo_list[i].Name, FileNameHoldingData);
            sprintf(Key, "%s_Age%i", KeyPrefix, i);
            sprintf(DataInt, "%i", foo_list[i].Age);
            WritePrivateProfileString("DataSection", Key, DataInt, FileNameHoldingData);
      }

      foo foo_fetch[9] ;
      
      for (i = 0;;++i)
      {
            sprintf(Key, "%s_Name%i", KeyPrefix, i);
            GetPrivateProfileString("DataSection", Key, "", foo_fetch[i].Name, sizeof(foo_list[i].Name), FileNameHoldingData);
            sprintf(Key, "%s_Age%i", KeyPrefix, i);
            foo_fetch[i].Age = GetPrivateProfileInt("DataSection", Key, -1, FileNameHoldingData);
            if (!strlen(foo_fetch[i].Name) || -1 == foo_fetch[i].Age) break;

            cout << foo_fetch[i].Name << ", " << foo_fetch[i].Age << endl;
      }

      system("pause");
      return 0;
}

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9801804
100-200 is not significant number for database. Text file or Registry (or some combination of them) will be enough. At runtime you can keep all the data in the memory.
Consider also mixed solution: some text data is kept in the text file, ini file or Registry, and binary data (like images) is kept in the binary file, like this:

Name = John
Image =  1.jpg
...
Name = Bill
Image =  10.jpg

This list may be loaded to memory and images are loaded only if necessary.

The important thing is whether you allow to run number of instances of your program simultaneously. If yes, prefered solution should be simple desktop database or Registry (which is updated immidiately).
0
 
LVL 3

Expert Comment

by:RJSoft
ID: 9804130
Axter you have a sample handy of using vector?

RJ
0
 
LVL 30

Expert Comment

by:Axter
ID: 9806424
>>Axter you have a sample handy of using vector?

http://axter.com/code/file_vector/file_vector.h
http://axter.com/code/file_vector/file_vector.cpp

http://axter.com/code/file_vector/file_vector.zip

The above code is some old code I worked on a long time ago.  If I remember right, the windows version works, but there's some problems with the UNIX version.

I think I got stuck on the bug for the UNIX version, and soon lost interest in it.

That should give you an idea on how to create a persistant STL container class.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question