PC Review


Reply
Thread Tools Rate Thread

binarywriter and buffer size?

 
 
=?Utf-8?B?ZnVuZG9vX2ty?=
Guest
Posts: n/a
 
      28th Dec 2006
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.
 
Reply With Quote
 
 
 
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      29th Dec 2006
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
 
Reply With Quote
 
=?Utf-8?B?ZnVuZG9vX2ty?=
Guest
Posts: n/a
 
      29th Dec 2006


"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?
 
Reply With Quote
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      29th Dec 2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
buffer size on HDs does size matter? Pdigmking DIY PC 22 6th Dec 2005 02:38 AM
Re: buffer size on HDs does size matter? John Doe Storage Devices 15 6th Dec 2005 02:38 AM
The size of buffer ad Microsoft C# .NET 1 27th Aug 2005 01:47 PM
HD Buffer Size Bob Simon Storage Devices 18 9th Mar 2005 07:34 PM
DVD Rom buffer size =?Utf-8?B?Q2hyaXM=?= Windows XP Help 0 14th Oct 2004 05:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 AM.