result = dbs.TransactionsDB.Get(null, ref keyEntry, ref dataEntry, DbFile.ReadFlags.None);
if (result == ReadStatus.Success)
{
byte[] buffer = dataEntry.Buffer;
MemoryStream ms = new MemoryStream(buffer);
results = (LinkedList<Transaction>)bf.Deserialize(ms);
}
This works fine as long as the dataEntry.Buffer size is not too small of course. So my main question is whether or not there is a way to pull that data back without specifying an initial buffer size? I could size the buffer appropriately, but in most cases, I would be over allocating, which wouldn't be a huge deal, but ideally I wouldn't allocate too much memory when I didn't have to.
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In a way, yes, but it requires two calls to the Get() function.
Have a look at the Overview demo app. There is a method GetNextRecord() in MainFrm.cs, and it deals with ReadStatus.BufferSmall.
Karl
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am currently doing the following:
I have a LinkedList object of a custom type.
Example:
LinkedList<TransactionType> transactions = new LinkedList<TransactionType>();
I continuously grow that list of transactions, and then I serialize that data using a BinaryFormatter and then write to DB doing the following:
//Write out transactions to database? memory?
DbEntry keyEntry;
DbEntry dataEntry;
keyEntry = dbs.Fmt.ToDbEntry<string>(key);
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, transactions);
dataEntry = DbEntry.InOut(ms.GetBuffer());
WriteStatus status = dbs.TransactionsDB.Put(null, ref keyEntry, ref dataEntry);
When it comes time to read, I'm doing the following:
LinkedList<Transaction> results = null;
DbEntry keyEntry;
DbEntry dataEntry = DbEntry.Out(new byte[1024]);
BinaryFormatter bf = new BinaryFormatter();
BerkeleyDb.ReadStatus result;
keyEntry = dbs.Fmt.ToDbEntry<string>(key);
result = dbs.TransactionsDB.Get(null, ref keyEntry, ref dataEntry, DbFile.ReadFlags.None);
if (result == ReadStatus.Success)
{
byte[] buffer = dataEntry.Buffer;
MemoryStream ms = new MemoryStream(buffer);
results = (LinkedList<Transaction>)bf.Deserialize(ms);
}
This works fine as long as the dataEntry.Buffer size is not too small of course. So my main question is whether or not there is a way to pull that data back without specifying an initial buffer size? I could size the buffer appropriately, but in most cases, I would be over allocating, which wouldn't be a huge deal, but ideally I wouldn't allocate too much memory when I didn't have to.
Thanks!
In a way, yes, but it requires two calls to the Get() function.
Have a look at the Overview demo app. There is a method GetNextRecord() in MainFrm.cs, and it deals with ReadStatus.BufferSmall.
Karl