🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #308791

Re: Kłopot z własną kolejką

#308791
From: zeus
Date: Sat, 13 Aug 2016 18:07
122 lines
4440 bytes
W dniu 2016-08-13 o 13:28, bartekltg pisze:
 > On 12.08.2016 22:38, zeus wrote:
 >> <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


 > Dlaczego to wszytko jest jako static?
 > Używasz tylko jednego obiektu tego typu?
 > I tak nie widzę sensu.

Że tak powiem z rozpędu. Miało być inaczej ale ostateczna wersja się 
zmieniła a static zostało. Ale nie wydaje się by było to przyczyną 
bałaganu. Poprawiłem -> test 5 pętli -> od (int64)1 do (int64.max - 5).
Test winXP32 - 3 błędy, pod 7 nie testowałem mam w pracy.
1 błąd zapis i 2 odczyt.
Przepraszam za wysłanie na priwa.

 >>
 >>     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: <nonnkt$72$2@sunflower.man.poznan.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.man.poznan.pl!not-for-mail
References: <nolc4h$2vo$1@sunflower.man.poznan.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.man.poznan.pl!not-for-mail
From: zeus <zeus@cbk.poznan.pl>
Newsgroups: pl.comp.lang.c
Subject: Re: Kłopot z
 własną kolejką
Date: Sat, 13 Aug 2016 20:07:24 +0200
Organization: POZMAN - http://www.man.poznan.pl/
Lines: 123
Message-ID: <nonnkt$72$2@sunflower.man.poznan.pl>
References: <nolc4h$2vo$1@sunflower.man.poznan.pl>
NNTP-Posting-Host: d214-107.icpnet.pl
Mime-Version: 1.0
X-Trace: sunflower.man.poznan.pl 1471111645 226 109.173.214.107 (13 Aug 2016 18:07:25 GMT)
X-Complaints-To: tomjab@man.poznan.pl
NNTP-Posting-Date: Sat, 13 Aug 2016 18:07:25 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/20100101 Thunderbird/38.7.2
In-Reply-To: <nolc4h$2vo$1@sunflower.man.poznan.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit