Page 1 of 1

OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 11:53 am
by SFSxOI
Not really coding questions per se... but...

If you use OpenLibrary with #PB_Any the library identifier number is auto generated from using #PB_Any.

The help says this::

"If a library will be opened with the same number as an already opened library, then the previously opened library will be automatically closed."

1. Is that number guranteed to be unique in the system for the library until the library is closed?

2. Does that mean for the same library....or.... can two different libraries have the same number forcing one to close even if the one being closed is still being used and still needed?

The help statement is somewhat ambiguous, and i need an answer for work purposes so I can revisit the use of OpenLibrary vs the API LoadLibrary and LoadLibraryEx i'm required to currently use in projects.

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:08 pm
by Shield
Yes, #PB_Any is unique...if you don't use too large IDs...that's what the 10'000 limit is for probably. :wink:
If you open another library with the same number, the first one will be closed and can't be used anymore.

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:11 pm
by SFSxOI
If the #PB_Any auto generated numbers are unique then how can there be another library number thats the same as an existing number?

Or is it that the numbers are only unique in the sense that only one of them can be present in the system at a time thus why forcing another library to close that had the same number previously generated?

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:13 pm
by luis
Because it's not generated, it's a constant you defined, like when you open a window or a library passing specifying "1".

#PB_Any returns a pointer to the internal PB structure in use, so it's unique, and cannot be reused.

http://www.purebasic.fr/english/viewtop ... 16#p284316

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:18 pm
by SFSxOI
The help says a number is auto generated, it doesn't say its returning a unique pointer.

How can there be another libarary with the same number forced to close if the number (or pointer) is unique?

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:20 pm
by SFSxOI
Read the link you gave, makes sense for #PB_Any by its self, but then why does the help indicate that a library is forced to close if it already has a number that has been generated by #PB_Any from another library being opened if the numbers are supposed to be unique?

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:23 pm
by luis
Can you paste the help section here ? In the "PureBasic objects" section I don't see anything like that.

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:34 pm
by Shield
If you use #PB_Any it's not possible to get the same ID twice...except if you defined the same
by specifying a constant. That's a reason why you shouldn't specify too large constant values...
that's also one of the reason why PB warns you, that your number might be too high.

IMHO, #PB_Any is always the way to go...get rid of using constants.

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 12:59 pm
by PMV
@SFSxOI
You are mixing up two completely different topics.
The PB Objectsystem has two ways to address an object.
Direct with an constant (value <10.000) or by using
#PB_Any ... the help mentions, that if you are using
the constant-way you can only address one object
of the same type (in this case a library) with the same
constant. If you have opened a library with constant
value 1 and you open a second library with constant
value 1, the first library will be closed. If you are using
#PB_Any you will get a unique value. If you use this
value in OpenLibrary() as the first parameter, you will
get an error like "constant over 10.000 not allowed!"

The PB objectsystem stores the reference to opended
objects in an array that is addressed by the constant
you have used (value < 10.000). So if you are using
a high value (like 9999) this arrays has 9999 elements.

If you are using #PB_Any, this internal array is not used.
The reference the function returns points directly to the
library object that PB stores internal. And to complete
this, this system is used for everything ... not only for
the libraries. :)

MFG PMV

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 1:30 pm
by luis
The point he's saying the help says the opposite.
the help indicate that a library is forced to close if it already has a number that has been generated by #PB_Any
That's why I'm asking him where this is written.

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 1:47 pm
by SFSxOI
I understand that the #PB_Any generated number should be unique, but the OpenLibrary help statement doesn't say that. The help says this for the OpenLibrary function:

"#Library A number to identify this library. #PB_Any can be used to autogenerate this number."
"If a library will be opened with the same number as an already opened library, then the previously opened library will be automatically closed."

The help never says the library number generated with #PB_Any is unique to that library only and can't be generated for another library as well and implies it is not unique because the next statement implies a library can be opened with the same number as a previously opened library forcing one to close, if the number was generated with #PB_Any then thats the number. Actually the help says "automatically closed" but thats the same thing as forcing the library to close if its in use when the "automatically closed" thing happens, in reference to certification its "forcing" and there is no such thing as "automatically" closing a library in use as doing something to stop something from functioning when its supposed to be functioning and remain functioning is acting contrary to the intended purpose of remaining in function so its forcing a condition that was not intended to "automatically" close a library in use. Overall this implies that #PB_Any can generate the same number for two different libraries when placed in context with OpenLibrary and force a library to close when it should not have been closed.

The statement implies that its possible for #PB_Any to generate a number that is not unique because it does not define that the number "auto generated" with #PB_Any is not the number being refered to in the help statement concerning same numbers. So while the official documentation via the help remains ambiguous on that point, I can't use OpenLibrary in projects dealing with government contracts because it makes it uncertifiable for use due to the ambiguous nature of the help statement.

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 2:01 pm
by luis
Are you implying something ? :)
SFSxOI wrote:I can't use OpenLibrary in projects dealing with government contracts because it makes it uncertifiable
Are you saying PB manual isn't rigorous ? Are you serious ? Didn't know that ?
PB manual continually changes for exactly these reasons, someone ask questions and other users put together their experiences, posts from fred/freak lost in the forum, and deductions from the actual behavior of the compiler to get an answer.

The link in my first post explains how the things works behind the scenes, and should be enough to understand what to expect (dynamic numbers are unique).

So your problem is with the documentation, not with knowing how things works.
If you need more you need to post in the documentation section asking to make these things unmistakeably clear, proposing your changes of course.
Nothing wrong with that !

PS: probably the clarification should be made in the section about the general rules for PB objects, not specifically for the OpenLibrary command.

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 2:19 pm
by SFSxOI
Yes, in a manner of speaking i'm saying that in relation to the OpenLibrary function in this case the manual is not "rigorous" to use your wording.

Its doesn't matter what is posted in the forum or how one explains it or what I know or how I explain it, I have to be able to trace back to official documentation for certification purposes in my case. Then yes, my problem is with the documentation. Its not a problem for me personally, but when it comes to my work its a problem in this aspect. An official statement from Fred would do it, that states the #PB_Any as used to auto generate the library number when used with the OpenLibrary function is unique to that library only and can not be duplicated with further use of #PB_Any for different libraries when using the OpenLibrary function.

So, i'll post over in the documentation section as you suggested maybe, did not post there to begin with because its not really a "bug" in the sense that its not exactly wrong but rather is more use specific and not clearly defined in relation to my needs.

Thanks for the discussion folks :)

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 3:54 pm
by PMV
Then yes, my problem is with the documentation. Its not a problem for me personally, but when it comes to my work its a problem in this aspect.
The documentation is just a help, a great one of course.
But to see how many people are working in this team,
and how huge the whole project is ... one thing is for
sure ... you can expect much more situations like that.

And this case with OpenLibrary() is even not the worst
one. Because here you know, that the help is misunderstood
able, but the real functionally is bulletproof. What will you
do if it is the other case? :lol: ... i wish you really good
luck with your work and PB ... but if it is that important
for you, use another language. :)

MFG PMV

Re: OpenLibrary and #PB_Any

Posted: Fri Dec 07, 2012 3:57 pm
by LuCiFeR[SD]
This is pretty straightforward really. How it is written, it is Advising the use of #PB_Any.
PB Manual -OpenLibrary() wrote:
Return value

Returns nonzero if the library was opened successfully and zero if not. If #PB_Any was used as the #Library parameter then the generated number for the library is returned on success.



The remarks below are warning you about clashing ID's. But it is not warning you at all about using #PB_any.
PB Manual -OpenLibrary() wrote: Remarks

If a library will be opened with the same number as an already opened library, then the previously opened library will be automatically closed.
See Also

CloseLibrary(), GetFunction(), prototypes
Supported OS

All
Although, personally I would rewrite the Remarks section for Open Library. Something along the lines of...
Rewritten Remarks wrote: If a library is opened with the same identifying number as an already opened library, then the previously opened library will be automatically closed.
Use #PB_Any to avoid these problems, or be absolutely certain that all identifying numbers are unique.
Thats the way I understand it anyway. I am pretty sure a member of the team will clarify it at some point :)