Article View: pl.comp.lang.c
Article #308785Kłopot z własną kolejką
From: zeus
Date: Fri, 12 Aug 2016 20:38
Date: Fri, 12 Aug 2016 20:38
100 lines
2962 bytes
2962 bytes
<MSVC2008 winXP32 i win7 64>
Problem polega na:
Po kompilacji "Debug" wszystko ładnie działa i nie ma problemów.
Po "Relase" też działa ale czasem wywala się błędami za każdym razem
innym - niezgodność typu, pisanie poza tablicą mimo, że nic nie wystaje itp.
Byłbym wdzięczny gdyby komuś się chciało na to zerknąć i powiedzieć co
skopałem.
Pozdrawiam
S.Z.
////////////////////////////////////////////////////////////////////////////
generic <typename T>
public ref class BlockRingBuffer sealed
{
private:
static array<T>^ buf; // array buffer
static System::Object ^syncroot; // object used to synchronize.
static Int32 size; // size declared
static Int32 head; // position in
static Int32 tail; // position out
static Int32 count; // occupied cells
Void Position(Int32 %pos)
{
if(++pos == buf->Length)
{
pos = 0;
}
}
public:
BlockRingBuffer(Int32 lenght)
{
size = lenght;
buf = gcnew array<T>(lenght);
syncroot = buf->SyncRoot;
count = 0;
}
Void Add(T value) // added value
{
System::Threading::Monitor::Enter(syncroot);
try
{
if(!count)
{
head = 0;
tail = 0;
if(buf->Length > size)
{
System::Array::Resize(buf, size);
}
}
if(count >= buf->Length)
{
System::Array::Resize(buf, buf->Length + 5);
head = count;
}
buf[head] = value;
Position(head);
count++;
System::Threading::Monitor::Pulse(syncroot);
}
finally
{
System::Threading::Monitor::Exit(syncroot);
}
}
bool Pop(T %value) // get content
{
bool ret = false;
System::Threading::Monitor::Enter(syncroot);
try
{
if(count)
{
value = buf[tail];
buf[tail] = T();
Position(tail);
count--;
ret = true;
}
}
finally
{
System::Threading::Monitor::Exit(syncroot);
}
return ret;
}
};
/////////////////////////////////////////////////////////////////////////
Technical Details
Message-ID:
<nolc4h$2vo$1@sunflower.man.poznan.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!news.nask.pl!news.nask.org.pl!newsfeed.pionier.net.pl!news.man.poznan.pl!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!news.nask.pl!news.nask.org.pl!newsfeed.pionier.net.pl!news.man.poznan.pl!not-for-mail From: zeus <zeus@cbk.poznan.pl> Newsgroups: pl.comp.lang.c Subject: Kłopot z własną kolejką Date: Fri, 12 Aug 2016 22:38:19 +0200 Organization: POZMAN - http://www.man.poznan.pl/ Lines: 100 Message-ID: <nolc4h$2vo$1@sunflower.man.poznan.pl> NNTP-Posting-Host: d214-107.icpnet.pl Mime-Version: 1.0 X-Trace: sunflower.man.poznan.pl 1471034321 3064 109.173.214.107 (12 Aug 2016 20:38:41 GMT) X-Complaints-To: tomjab@man.poznan.pl NNTP-Posting-Date: Fri, 12 Aug 2016 20:38:41 +0000 (UTC) X-Mozilla-News-Host: news://news.man.poznan.pl:119 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit