🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#308780
From: bartekltg
Date: Sat, 13 Aug 2016 11:28
109 lines
3803 bytes
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.

>
>     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: <non09k$fna$1@node1.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!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!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: bartekltg <bartekltg@gmail.com>
Newsgroups: pl.comp.lang.c
Subject: Re: Kłopot z
 własną kolejką
Date: Sat, 13 Aug 2016 13:28:52 +0200
Organization: ATMAN - ATM S.A.
Lines: 110
Message-ID: <non09k$fna$1@node1.news.atman.pl>
References: <nolc4h$2vo$1@sunflower.man.poznan.pl>
NNTP-Posting-Host: 89-70-119-159.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: node1.news.atman.pl 1471087732 16106 89.70.119.159 (13 Aug 2016 11:28:52 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Sat, 13 Aug 2016 11:28:52 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To: <nolc4h$2vo$1@sunflower.man.poznan.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit