Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing back cache to the db file

 
Sham Delaney
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to attempt to write my memory cache to the db file.
How I was thinking about doing this is to seek back the file pointer location where the data part of the db begins.

I am trying to assign the string to a byte array, but when i do this, the byte array is shortened to the same length of the string. The end of the byte array is missing.
Hence the fields are not maintaining their fixed length.

Can anyone advise me of a better way of doing this. There must be a simpler API or algorithm that I dont know of.

Thanks

Here is the code I am trying.

 
Sham Delaney
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be ok to hold the file pointer position before a field has been written...and then seek on 32 (or 64/6/8) places - whichever was neccessary...to write the next field ?
Can someone advise please?
 
Sham Delaney
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just very confused as to whether to append to the file and write over the existing records...or overwrite the file completely - with new header information and all.

Please help.
 
Jimmy Chen
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's also what I want to know
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12012
218
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it would be overkill to overwrite the entire file every time you want to update an individual record.

While you could write each field then seek to the next field position, this would be very inefficient, and would unnecessarily lower concurrent operations.

Have you looked at what options you have for working with a larger byte array - for example one the size of the entire record? Possibly a method that can fill the entire array with the fill character to start with, then methods that allow you to copy bytes into a subset of that array?

Perhaps you could look at the Arrays class and the System class to see if there is anything that might help.

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic