By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Filestream and BinaryWriter lengths?

P: 1
I am using BinaryWriter to log data using a Structure in VB NET Compact Framework 3.5 and I do this by appending a block of the individual structure items as follows:
Expand|Select|Wrap|Line Numbers
  1.         Dim filestream As FileStream = New FileStream("mlog.bin",   FileMode.Append)
  2.         Dim fwrite As BinaryWriter = New BinaryWriter(filestream)
  4.         mdat.rtime = Now 'load the present time' 
  6.         fwrite.Write(mdat.rtime)
  7.         fwrite.Write(mdat.Ax4)
  8.         fwrite.Write(mdat.Ax3)
  9.         fwrite.Write(mdat.Ax2)
  10.         fwrite.Write(mdat.Ax1)
  11.         fwrite.Write(mdat.KWHA)
  12.         fwrite.Write(mdat.KWHB)
  13.         fwrite.Write(mdat.KWHC)
  14.         fwrite.Write(mdat.Stat)
  15.         fwrite.Write(mdat.AN1)
  16.         fwrite.Write(mdat.AN2)
  18.         fwrite.Close()
  19.         filestream.Close()
This code works fine but I am unable to figure out why Binary writer stores this in 63 bytes?
The first item mdat.rtime is a DateTime and I assume it is stored as a string using binary writer because I recover it OK with BinaryReader when the read variable as a string? All the other 10 items are 4 byte Singles variables?

When I check the length of mdat.rtime it tells me that it is 8 bytes long so I assume that BinaryWriter should write this block of data as 48bytes in total but checking the filestream length tell me it is 63 bytes long - why?

I have noticed that this length changes from 60 - 63 bytes depending on what format the regional settings are ? - but the mdat.rtime length always remains 8 bytes?

I need to know how BinaryWriter stores DateTime and exactly how many bytes are stored so that I can recover my data into arrays of equal size (when more data is logged) - and also this needs to be known for whatever the regional setting are set to?

Any assistance would be most appreciated?
Apr 29 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.