Please add a return value for CloseLibrary

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Please add a return value for CloseLibrary

Post 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
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: Please add a return value for CloseLibrary

Post 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?
The best preparation for tomorrow is doing your best today.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Please add a return value for CloseLibrary

Post by Trond »

If you coded your program correctly, you don't need the Is*() functions.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Please add a return value for CloseLibrary

Post 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.
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: Please add a return value for CloseLibrary

Post 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.
The best preparation for tomorrow is doing your best today.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Please add a return value for CloseLibrary

Post by DoubleDutch »

Can we have something like CountImages()?
+1 and also CountWindows, CountGadgets, etc will be useful for debug stats.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply