dynamic tables and serialization of vectors

N

Ninan Thomas

I am posting this to two not so directly related groups. But i feel it
belongs to both.
I am trying to create a database at runtime in Berkeley DB and insert
and retrieve values from it. So I cannot pre compile the schema into a
C++ struct, as explained in the sleepycat documentation.
1) What is the most effecient way to do this? (This is a Berkeley DB
question)

Now coming to the C++ part. To explain the context to C++ newsgroup
readers, Berkeley DB has the concept of key , value pairs to insert
data
Dbt key, value
struct Dbt {
void *data;
int size;
----
-----// some other not so relevant fields
}

They are defined as generic pointers.Also one has to enter the size
in bytes occupied by the pointer.
The solution I came up with is to define a vector.
vector<myType> *x
where myType is a union of int , string and may be some more data
types like timestamp.
Insert the column values into the vector.
My question is how to convert x into a void * pointer and serialize
the data.
I need to find the length in bytes occupied by vector to serialize it.
How to find it. Is raw_storage_iterator the way to go?
 
?

=?ISO-8859-1?Q?Juan_Antonio_Dom=EDnguez_P=E9rez?=

Ninan said:
I am posting this to two not so directly related groups. But i feel it
belongs to both.
I am trying to create a database at runtime in Berkeley DB and insert
and retrieve values from it. So I cannot pre compile the schema into a
C++ struct, as explained in the sleepycat documentation.
1) What is the most effecient way to do this? (This is a Berkeley DB
question)

You are at the rigth way. Keep the elements using a vector, easy to use
with your algorithms, and keep persistence in a bdb. When you want to
write the db file, do dynamic allocation and write the complete buffer.
You cant do it any other way, because you cannot be confident of the
vector implementation; anyway, the raw_storage_iterator will not be of
any use for you, because the elements are an union of diferent types and
you must (?) choose in any way the member of the union you want to storage.
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top