🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#308789
From: Przemek Biernat
Date: Mon, 05 Dec 2016 17:18
103 lines
3868 bytes
On Friday, August 12, 2016 at 10:40:01 PM UTC+2, 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
> 
> 	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;
> 	}
> };
> /////////////////////////////////////////////////////////////////////////

Nie działa pewnie z tego samego powodu co templatowana metoda czysto virtualna. A czasem tak bardzo by się przydała taka własnie metoda, którą można by przeciążyć w klasach pochodnych.
Technical Details
Message-ID: <6c989151-df8e-4672-adc0-cc9c5a854db2@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!feeder.erje.net!1.eu.feeder.erje.net!newspeer1.nac.net!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!p16no2895226qta.1!news-out.google.com!j8ni5461qtc.0!nntp.google.com!n6no2896196qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <nolc4h$2vo$1@sunflower.man.poznan.pl>

Show Full Headers
Complete Article Headers
X-Received: by 10.99.1.201 with SMTP id 192mr30669907pgb.156.1480958281827;        Mon, 05 Dec 2016 09:18:01 -0800 (PST)
X-Received: by 10.157.8.134 with SMTP id 6mr3728675otf.17.1480958281761; Mon, 05 Dec 2016 09:18:01 -0800 (PST)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!feeder.erje.net!1.eu.feeder.erje.net!newspeer1.nac.net!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!p16no2895226qta.1!news-out.google.com!j8ni5461qtc.0!nntp.google.com!n6no2896196qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Mon, 5 Dec 2016 09:18:01 -0800 (PST)
In-Reply-To: <nolc4h$2vo$1@sunflower.man.poznan.pl>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.205.140.255; posting-account=JqeG5AoAAAAiFyQBrqF1gF5A1eLVPTrJ
NNTP-Posting-Host: 87.205.140.255
References: <nolc4h$2vo$1@sunflower.man.poznan.pl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6c989151-df8e-4672-adc0-cc9c5a854db2@googlegroups.com>
Subject: Re: Kłopot z
 własną kolejką
From: Przemek Biernat <biernat.przemyslaw@gmail.com>
Injection-Date: Mon, 05 Dec 2016 17:18:01 +0000
Lines: 110
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit