473,395 Members | 1,452 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,395 software developers and data experts.

Truncating a Stream...

Is it possible to truncate a MemroyStream to free up the space up to the
current position?

I wantes to be able to just keep dumping bytes into a stream and then read
the stream as needed. After the read, free up the portion of the stream I
read, esentially making the first unread byte the first byte in the stream.

Thanks.

Jerry
Sep 26 '06 #1
3 5020
rlrcstr <rl*****@discussions.microsoft.comwrote:
Is it possible to truncate a MemroyStream to free up the space up to the
current position?

I wantes to be able to just keep dumping bytes into a stream and then read
the stream as needed. After the read, free up the portion of the stream I
read, esentially making the first unread byte the first byte in the stream.
MemoryStreams are basically backed by a byte array. You'd need to make
a copy of the part of the byte array you still need, and either create
a new MemoryStream or reset the current one. Your Position property is
likely to be wrong afterwards though...

It would possibly be easier to write such a stream class yourself than
to use MemoryStream. For one thing, you could make it use several
chunks of memory rather than a single byte array, which would make it
cheaper to throw the start away.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 26 '06 #2
Thanks Jon. THat's basically what I ended up doing.

"Jon Skeet [C# MVP]" wrote:
rlrcstr <rl*****@discussions.microsoft.comwrote:
Is it possible to truncate a MemroyStream to free up the space up to the
current position?

I wantes to be able to just keep dumping bytes into a stream and then read
the stream as needed. After the read, free up the portion of the stream I
read, esentially making the first unread byte the first byte in the stream.

MemoryStreams are basically backed by a byte array. You'd need to make
a copy of the part of the byte array you still need, and either create
a new MemoryStream or reset the current one. Your Position property is
likely to be wrong afterwards though...

It would possibly be easier to write such a stream class yourself than
to use MemoryStream. For one thing, you could make it use several
chunks of memory rather than a single byte array, which would make it
cheaper to throw the start away.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 26 '06 #3
Sounds to me like you want / need some implementation of a CircularBuffer
class.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rlrcstr" wrote:
Is it possible to truncate a MemroyStream to free up the space up to the
current position?

I wantes to be able to just keep dumping bytes into a stream and then read
the stream as needed. After the read, free up the portion of the stream I
read, esentially making the first unread byte the first byte in the stream.

Thanks.

Jerry
Sep 26 '06 #4

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

Similar topics

4
by: qazmlp | last post by:
Can anybody comment(& suggest improvements) on the following implementation that is for truncating the character buffer contents to the desired length? Truncating char array void...
5
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hello, Can someone over here help me in truncating a float variable. I mean if PI=3.14159 ...How can I get to read the first two or first three decimal values with out rounding them. Any...
1
by: andrewcw | last post by:
Should be simple, I open fileX, then serialize my content back out ( with position set to 0 ). This works well as long as my new output is larger than the old file input. But when my output is...
1
by: Jitesh Sinha | last post by:
Hi, I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal behaviour of System.Web.mail class. It was truncating the message body after 3,071 character. The code i was testing...
3
by: rangermccoy | last post by:
Hello there, What are the best php/c libraries for handling media including images, video, and music? I would like to manipulate media dfiles, including watermarking, thumbnailing,...
2
by: William | last post by:
I am attempting to write an XmlDocument to file, but for some reason it will only write 2048 characters of the document even though when I stop it in the debugger ALL of the document is there. ...
1
by: Daniel Wilson | last post by:
We have a stored procedure that is giving us an XML representation (using FOR XML Explicit) of a sales order. Sometimes that evaluats to quite a long string. Unfortunately, this XML string is...
1
by: sconnors | last post by:
I am currently working on an application that runs on Windows XP SP2 with .NET 2.0, Linux 2.4.19-16mdkenterprise and Solaris 5.9. The language is C++. When I compare the output numbers, Windows...
21
by: Jenn | last post by:
I have a memo field in a report that is truncating at 255 characters. I've tried the following w/no success: 1. Grow/Shrink option is yes. 2. "Group By" changed to "first". 3. "Group by" changed to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.