Click here to Skip to main content
15,860,972 members
Home / Discussions / C#
   

C#

 
GeneralRe: Writing and Reading on MemoryStream? Pin
Stefan Troschuetz19-Apr-05 9:12
Stefan Troschuetz19-Apr-05 9:12 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl19-Apr-05 9:40
Scott Serl19-Apr-05 9:40 
GeneralRe: Writing and Reading on MemoryStream? Pin
Snowjim19-Apr-05 10:16
Snowjim19-Apr-05 10:16 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl19-Apr-05 11:35
Scott Serl19-Apr-05 11:35 
GeneralRe: Writing and Reading on MemoryStream? Pin
Snowjim20-Apr-05 3:50
Snowjim20-Apr-05 3:50 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl20-Apr-05 8:29
Scott Serl20-Apr-05 8:29 
GeneralRe: Writing and Reading on MemoryStream? Pin
Snowjim20-Apr-05 8:40
Snowjim20-Apr-05 8:40 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl20-Apr-05 11:04
Scott Serl20-Apr-05 11:04 
.Net memorystreams will increase in size if you keep writing to them (unless you use a fixed length byte array as its buffer).

If you want to write to the end and read from the front without running out of memory, you can manage your own byte arrays. There are several ways I can think of to manage array size:
1. When you read from the front of the stream, move the content: array.Copy(buf, readlength, buf, remainingLength). This technique might not perform well depending on the implementation of array.Copy.
2. Use a short list of byte arrays for the stream. When your write would go past the end of the array, create a new array (or manage a pool of existing arrays) to put the overflow in. Add the new array to a collection. When you read the past the end of an array, you can remove it from the collection.
3. Use a circular system. When your write would go past the end of the byte array, use any unused space at the front of the array (unused, since you have already read the data and moved the read position further along the array).

I don't know how .Net handles these issues in streams. I would probably try method 2 above, since it doesn't require collision testing like method 3. Method 2 is also easy to optomize to various buffer sizes and could perform quite well. Method 1 could work also, but I don't know how good the performance is of Array.Copy.
GeneralRe: Writing and Reading on MemoryStream? Pin
Snowjim20-Apr-05 11:42
Snowjim20-Apr-05 11:42 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl21-Apr-05 8:22
Scott Serl21-Apr-05 8:22 
GeneralCrystalReports From Pull -> Push Pin
V.18-Apr-05 23:49
professionalV.18-Apr-05 23:49 
GeneralFilling the Textbox Pin
Anonymous18-Apr-05 23:36
Anonymous18-Apr-05 23:36 
Generalplease help me with this Pin
snouto18-Apr-05 23:28
snouto18-Apr-05 23:28 
GeneralRe: please help me with this Pin
S. Senthil Kumar19-Apr-05 0:52
S. Senthil Kumar19-Apr-05 0:52 
GeneralTransparent ListBoxes Pin
zagzagzag18-Apr-05 23:24
zagzagzag18-Apr-05 23:24 
GeneralRe: Transparent ListBoxes Pin
Anonymous19-Apr-05 1:05
Anonymous19-Apr-05 1:05 
GeneralRe: Transparent ListBoxes Pin
Dave Kreskowiak19-Apr-05 4:19
mveDave Kreskowiak19-Apr-05 4:19 
GeneralRe: Transparent ListBoxes Pin
zagzagzag19-Apr-05 9:10
zagzagzag19-Apr-05 9:10 
GeneralMusic Programming Pin
Deniz Oflaz18-Apr-05 23:11
Deniz Oflaz18-Apr-05 23:11 
GeneralRe: Music Programming Pin
pjc*19-Apr-05 3:27
pjc*19-Apr-05 3:27 
GeneralRe: Music Programming Pin
RNEELY19-Apr-05 4:13
RNEELY19-Apr-05 4:13 
GeneralCreating OdbcDataAdapter object with Select statement that has spaces in the fileName Pin
chukkykzn18-Apr-05 22:58
chukkykzn18-Apr-05 22:58 
GeneralHigh CPU usage when using Toolbar Pin
MasudM18-Apr-05 22:24
MasudM18-Apr-05 22:24 
GeneralHelp -- TreeView, How to Sort only a Part of TreeView Nodes Pin
Umair Tariq18-Apr-05 21:18
Umair Tariq18-Apr-05 21:18 
GeneralRe: Help -- TreeView, How to Sort only a Part of TreeView Nodes Pin
CStiefeling19-Apr-05 8:30
CStiefeling19-Apr-05 8:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.