-
Path: news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!p
ostnews.google.com!x25g2000yqj.googlegroups.com!not-for-mail
From: Selvin <p...@g...com>
Newsgroups: pl.comp.programming
Subject: Re: Streamin c#
Date: Wed, 1 Sep 2010 08:31:09 -0700 (PDT)
Organization: http://groups.google.com
Lines: 66
Message-ID: <0...@x...googlegroups.com>
References: <i53218$sgk$1@news.onet.pl>
NNTP-Posting-Host: 217.97.163.80
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1283355069 8968 127.0.0.1 (1 Sep 2010 15:31:09 GMT)
X-Complaints-To: g...@g...com
NNTP-Posting-Date: Wed, 1 Sep 2010 15:31:09 +0000 (UTC)
Complaints-To: g...@g...com
Injection-Info: x25g2000yqj.googlegroups.com; posting-host=217.97.163.80;
posting-account=R8EpSwoAAADeCYcG96LM5BAc_tdIdesQ
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.4
(KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4,gzip(gfe)
Xref: news-archive.icm.edu.pl pl.comp.programming:186756
[ ukryj nagłówki ]po co stream :) kolejka nie moze byc?
jak chcesz to mozesz to odziedziczyc po System.IO.Stream
public class MyBuffer
{
Queue<MemoryChunk> buffers = new Queue<MemoryChunk>();
object readlock = new object();
public uint AvailableDataLength { get; private set; }
public void Write(byte[] data, int offset, int count)
{
var mem = AllocateMemoryChunk(count);
Buffer.BlockCopy(data, offset, mem.Buffer, 0, count);
lock (readlock)
{
buffers.Enqueue(mem);
AvailableDataLength += count;
}
}
public int Read(byte[] buffer, int offset, int count)
{
int toread = 0;
lock (readlock)
{
if (buffers.Count != 0)
{
var buf = buffers.Peek();
toread = buf.Buffer.Length - buf.Offset;
int off = buf.Offset;
if (count >= toread)
buffers.Dequeue();
else
{
toread = count;
buf.Offset += toread;
}
Buffer.BlockCopy(buf.Buffer, off, buffer, offset,
toread);
AvailableDataLength -= toread;
}
return toread;
}
}
private MemoryChunk AllocateMemoryChunk(int newSize)
{
//zawsze mozna zrobic z tego pool zeby nie tworzyc nowych
MemoryChunk chunk = new MemoryChunk(newSize);
return chunk;
}
private class MemoryChunk
{
internal byte[] Buffer;
internal int Offset = 0;
internal MemoryChunk(uint bufferSize)
{
Buffer = new byte[bufferSize];
Offset = 0;
}
}
}
Następne wpisy z tego wątku
Najnowsze wątki z tej grupy
- Do czego nadaje się QDockWidget z bibl. Qt?
- Bibl. Qt jest sztucznie ograniczona - jest nieprzydatna do celów komercyjnych
- Co sciaga kretynow
- AEiC 2024 - Ada-Europe conference - Deadlines Approaching
- Jakie są dobre zasady programowania programów opartych na wtyczkach?
- sprawdzanie słów kluczowych dot. zła
- Re: W czym sie teraz pisze programy??
- Re: (PDF) Surgical Pathology of Non-neoplastic Gastrointestinal Diseases by Lizhi Zhang
- CfC 28th Ada-Europe Int. Conf. Reliable Software Technologies
- Młodzi programiści i tajna policja
- Ada 2022 Language Reference Manual to be Published by Springer
- Press Release - AEiC 2023, Ada-Europe Reliable Softw. Technol.
- Ada-Europe - AEiC 2023 early registration deadline approaching
- Ada-Europe Int.Conf. Reliable Software Technologies, AEiC 2023
- Ile cykli zajmuje mnożenie liczb 64-bitowych?
Najnowsze wątki
- 2024-07-11 Tokarze CNC czyli ciężkie życie prototypiarza
- 2024-07-12 Zgody na przetwarzanie danych
- 2024-07-13 IObit Uninstaller Pro 13.6.0.5 Multilingual: Installation Guide
- 2024-07-12 stare graty młode kozy
- 2024-07-11 8080
- 2024-07-13 Przyłącze dolne grzejnika
- 2024-07-13 IObit Uninstaller Pro 13.6.0.5 Multilingual Overview
- 2024-07-12 Czym wykonać otwór fi 100 w betonie komórkowym?
- 2024-07-12 Warszawa => Senior Rust Software Engineer <=
- 2024-07-12 Warszawa => Business Unit Manager (Recruitment Business) <=
- 2024-07-12 Warszawa => Head of WMS Competence Center for IT&D Contract Logistics
- 2024-07-12 Warszawa => Head od WMS Competence Center dla IT&D (Blue Yonder) <=
- 2024-07-12 Kraków => Ruby Backend Developer <=
- 2024-07-12 Warszawa => UX/UI Designer <=
- 2024-07-12 Częstochowa => Specjalista ds. Marketingu (E-Commerce) <=