473,507 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filestream and BinaryWriter lengths?

1 New Member
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)
  3.  
  4.         mdat.rtime = Now 'load the present time' 
  5.  
  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)
  17.  
  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?
Colin
Apr 29 '10 #1
0 1075

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

Similar topics

0
4501
by: John | last post by:
I've got multiple threads and processes that write to same file. Before writing all threads / processes first lock part of file and then write to file. If one thread / process locks file, another...
0
1488
by: Bohus | last post by:
I want that my thread sleeps until file is unlocked, but if I wait for signaled state of FileStream handle, it does not work and ARE.WaitOne() function returns immediately, even if file is locked...
17
3778
by: Filip Strugar | last post by:
Considering that the BinaryWriter/BinaryReader object closes the underlaying stream upon being gc collected, is the following code correct, and if it is what is the reason preventing BinaryWriter...
1
6214
by: Claire | last post by:
I'm writing from a serial port into a MemoryStream via a BinaryWriter in my protocol object. After I've filled the memorystream, which is approx 200KB in size, I then pass it up to my datahandler...
1
2313
by: Barguast | last post by:
Is it necessary to call the close method for every BinaryWriter that I create? Or is it just a way to close the underlying stream? For example is it OK to do the following: private void...
3
1787
by: Eugene | last post by:
I'm trying to write a class which uses BinaryWriter as its base but allows for queuing of write requests Public Class QueuedBinaryWriter Inherits BinaryWriter I override all the Write methods...
5
8363
by: TC | last post by:
I just noticed that the Stream class has a Seek method, which implies that a FileStream object can be used to manipulate a random-access file. Before now, I assumed that a Stream, as its name...
1
3744
by: Tony | last post by:
Hello, I a byte array and i put to remote class (to blocks) I read byte array from a file : dim fs as FileStream = File.Open(filename, FileMode.Open); dim data() as byte = new...
2
2064
by: John | last post by:
I am trying to familiarize myself with filestreams, but I have run into the following issues. I am hoping that someone can shed some light on these issues for me please. I am using the...
6
3047
by: dantz | last post by:
Hi everyone, can someone please explain to me why does the strings will have the same text when saved in a file using a binarywriter? I mean when other types are saved usually it was converter in...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.