Page 2 of 2

Re: Please add a return value for CloseLibrary

Posted: Mon Oct 11, 2010 6:33 pm
by PMV
freak wrote:Keep this in mind:
All IsXXX() commands are expensive operations, because the only way to validate #PB_Any objects is to look at all of them and see if one matches. That won't matter if you have just two libraries open but if we are talking about a few hundred gadgets or images, things look different. So better don't get into that habit.

In fact: A correctly written program should have no need to call any IsXXX() function ever since you can always tell on object creation whether it succeeded or failed, and you know when you free the object so there is no reason for a confusion of weather an object is valid or not. These functions are a debugging tool, nothing else.
oh :?
I'm glad i used the IsXXX() function here, i had a feeling something like this would happen. :lol:
Ok, got it. I can't remember that i read it in the manual, but which case needs than a "IsXXX()-function"? I mean if a object-create-function returns a number, there must be a pb-object behind it, so the IsXXX()-function will return #True? Something i oversee?

MFG PMV

Re: Please add a return value for CloseLibrary

Posted: Mon Oct 11, 2010 7:04 pm
by KJ67
Well, I use IsThread() a lot since I try to avoid to many semaphores and other signaling methods.
Maybe I should rethink this too, or is this overhead mainly for 'static' objects?

Re: Please add a return value for CloseLibrary

Posted: Mon Oct 11, 2010 7:27 pm
by Trond
If you coded your program correctly, you don't need the Is*() functions.

Re: Please add a return value for CloseLibrary

Posted: Mon Oct 11, 2010 7:45 pm
by Demivec
KJ67 wrote:Well, I use IsThread() a lot since I try to avoid to many semaphores and other signaling methods.
Maybe I should rethink this too, or is this overhead mainly for 'static' objects?
I think IsThread() shouldn't be too expensive to execute because it is reasonable to keep the number of threads from being too high (may change in the future). The other signaling method's execution time may be longer as well.

Re: Please add a return value for CloseLibrary

Posted: Mon Oct 11, 2010 9:06 pm
by KJ67
For object that can be fully controlled Is*() may be unnecessary, but for dynamic thing outside direct control it my be harder.

I've been using a setup like below to spit up chores on a for me unknown amount of threads.

Code: Select all

Define MySem=CreateSemaphore(GetCPUCount())

Procedure MyThread(x)
  WaitSemaphore(MySem)
  *ToDO=ReciveInternalMessage(Str(x))
  ;Do stuff
  SendInternalMessage("Main",*result)
  SignalSemaphore(MySem)
EndProcedure

ForEach PartsOfWork()
  n+1
  SendInternalMessage(Str(n),PartsOfWork())
  AddElement(T()): T()=CreateThread(@MyThread(),n)
Next

; Now, to see when the work gets completed I can go with;
; * IsThread(T()) simple,but maybe not so efficeint.
; * WaitThread(T(),n), even with a small timeout it's still blocking which may be a issue
; * Try/WaitSemaphore(MySem), nicer - but also complicates the handling to 
;                             avoid competing with the Threads for these Semaphores.
The pure Semaphore version may be the more 'correct', but I can't really agree with the statement that "Is*() is not needed". Sometimes it simplifies the programming very much - same goes for the old love/hate commando Goto.

There is always a trade-of in performance vs. needed effort to complete a function, I will for sure not argue about that, but the for me interesting thing now is how expensive this lazy version really is.

Anyhow, this is not the thread for this kind of discussion, excuse me Mistrel for going off-topic.

Re: Please add a return value for CloseLibrary

Posted: Mon Oct 18, 2010 10:57 am
by DoubleDutch
Can we have something like CountImages()?
+1 and also CountWindows, CountGadgets, etc will be useful for debug stats.