🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by zeus Fri, 12 Aug 2016 20:38
Kłopot z własną kolejką
#308785
Author: zeus
Date: Fri, 12 Aug 2016 20:38
100 lines
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;
	}
};
/////////////////////////////////////////////////////////////////////////
Re: Kłopot z własną kolejką
#308780
Author: 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;
>     }
> };
> /////////////////////////////////////////////////////////////////////////
Re: Kłopot z własną kolejką
#308791
Author: 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;
 >>     }
 >> };
 >> 
/////////////////////////////////////////////////////////////////////////
 >
Kłopot sam się dziwnie rozwiązał
#308788
Author: zeus
Date: Sun, 14 Aug 2016 05:27
42 lines
2282 bytes
>> 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.

Problem się sam rozwiązał:

Poprawiłem a potem jeszcze (uporządkowałem) zamieniłem miejscami zmienne
	
	static System::Object ^syncroot;
	array<T>^ buf;
	Int32 count;  	
	Int32 size;
	Int32 head;
	Int32 tail;

Problem się skończył - czy ktoś potrafi wytłumaczyć o co chodzi?
10 testów i oczom nie wierzę...

Bardzo dziękuję za pomoc

Pozdrawiam
S.Z.
Re: Kłopot z własną kolejką
#308789
Author: 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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads