473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

binarywriter and buffer size?

Check the following code

///Buffer to store the data
byte[] data = new byte[DEFAULT_BUFF_SIZE];

///Create a memory stream from the buffer
MemoryStream memStream = new MemoryStream(data);

///Binary writer
BinaryWriter newData = new BinaryWriter(memStream);

///Write the data
newData.Write(Convert.ToUInt32(nResourceID));

///need to identify available free size in data
///newData.Write(Convert.ToUInt32(nResLength));

/// write(byte[], index, count);
newData.Write(
buffer having data more than DEFAULT_BUFF_SIZE,
anywhere in the memory buff,
should fill up to DEFAULT_BUFF_SIZE);
Now the problem is what is the best possible solution to know how much data
is written in the buffer i.e. "data" variable?

I need to stick to the DEFAULT_BUFF_SIZE limit while writing the data

BinaryWriter gives me more flexibility to write any kind of data?
MemoryStream only accepts the byte kind of data? which is not readily
available.
Dec 28 '06 #1
3 6603
fundoo_kr wrote:
Check the following code

///Buffer to store the data
byte[] data = new byte[DEFAULT_BUFF_SIZE];

///Create a memory stream from the buffer
MemoryStream memStream = new MemoryStream(data);

///Binary writer
BinaryWriter newData = new BinaryWriter(memStream);

///Write the data
newData.Write(Convert.ToUInt32(nResourceID));

///need to identify available free size in data
///newData.Write(Convert.ToUInt32(nResLength));

/// write(byte[], index, count);
newData.Write(
buffer having data more than DEFAULT_BUFF_SIZE,
anywhere in the memory buff,
should fill up to DEFAULT_BUFF_SIZE);

Now the problem is what is the best possible solution to know how much data
is written in the buffer i.e. "data" variable?
MemoryStream has 3 properties:
Capacity
Length
Position

Do they give you what you want ?

Arne
Dec 29 '06 #2


"Arne Vajhøj" wrote:
MemoryStream has 3 properties:
Capacity
Length
Position

Do they give you what you want ?

Arne
Thanks for your reply but they don't seem to work, since i have assigned the
buffer it is giving me the same amount of value in this case it is 1000.

Moreover i have tried even after flushing the binarystream.
Still i don't find any way to identify the amount of bytes used up.
In C since every write used to return the number of bytes written, something
similar i am looking atleast?
Dec 29 '06 #3
fundoo_kr wrote:
"Arne Vajhøj" wrote:
>MemoryStream has 3 properties:
Capacity
Length
Position

Do they give you what you want ?

Thanks for your reply but they don't seem to work, since i have assigned the
buffer it is giving me the same amount of value in this case it is 1000.
Weird.

using System;
using System.IO;

namespace E
{
public class MainClass
{
public static void Main(string[] args)
{
byte[] data = new byte[1000];
MemoryStream memStream = new MemoryStream(data);
BinaryWriter newData = new BinaryWriter(memStream);
newData.Write(123);
Console.WriteLine(memStream.Position);
}
}
}

writes 4 at PC !

Arne
Dec 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Miller | last post by:
I have a char array and when I write it to a file using BinaryWriter the position of the pointer is the size of the array + 1. For example: writing char leaves the pointer at position 26 after...
17
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
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
by: dsmith | last post by:
I need to write a data array out to disk, but unfortunately am running into performance issues. The function is essentially: private ushort theInt16Array = new ushort; public void...
4
by: Paul Steele | last post by:
I am writing a client/server application that communicates over tcp. The code I use to initiate the connection is as follows: NetworkStream networkStream = new NetworkStream(ClientSocket);...
5
by: Boris | last post by:
// Example BinaryWriter bw = new BinaryWriter(new FileStream("c:\Test.bin",FileMode.Append)); BinaryWriter.Write writes data to the stream. However, it doesn't automatically flush data any...
1
by: keithv | last post by:
Hi, The msdn doc for MemoryStream has two conflicting statements about accessing a MemoryStream's buffer after it's been closed: The buffer is still available on a MemoryStream once the...
3
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...
3
by: philip | last post by:
If I execute that : Dim Temp as string = "This is a text" Dim sw As StreamWriter Dim fullFileName as string = "c:\text.txt" sw = New StreamWriter(fullFilename) sw.Write(temp) sw.Close() ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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
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...

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.