473,769 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5081
rlrcstr <rl*****@discus sions.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.co m>
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*****@discus sions.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.co m>
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
21984
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 truncateCharArray(int maxLength , char * buffer ) { if ((0 == buffer) || !(0 < maxLength)) return; if (maxLength < strlen(buffer))
5
5432
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 suggestions are appreciated. I am BEGINNER TO C PROGRAAMING. Thanks
1
2631
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 smaller, it does not overwrite all the data and so I get the new output plus the overhanging piece of FileX. What the quick way to let resize the stream to just my new
1
2520
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 was: Import Namespace="System.Web.Mail" Dim aa as new StringBuilder(600010) Dim i as Integer
3
2262
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, truncating, etc. I know there's the GD llibrary for images.
2
2861
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. Code snippet is as follows: XmlDocument xml = new XmlDocument(); xml.LoadXml(Encoding.UTF8.GetString(btResponse)); XmlTextWriter w = new XmlTextWriter("..\\..\\..\\xml\\Test.xml", null); xml.WriteTo(w); // will not write anything after 2048...
1
1640
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 being truncated to 2034 characters before we can do anything with it. Here's our code: Private Sub LoadXML()Dim dtaXML As New SqlClient.SqlDataAdapter("MyStoredProcedureThatReturnsXML", "MyConnectionString")Dim dsXML As New...
1
2131
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 rounds the numbers up (for example: 13030.65 becomes 13030.7 - precision is 6) and in Linux/Solaris the number is rounded down or more likely truncated (for example: 13030.65 becomes 13030.6). I can set the precision on the ostream or output file...
21
25494
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 "last" 4. took out memo field, saved query, and reinserted memo field. nothing seems to be fixing this bug. Please help! any suggestions are greatly appreciated.
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9981
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7396
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.