Page 1 of 2

Thinking of buying PureBasic but have some questions :)

Posted: Fri Sep 28, 2012 11:13 am
by tastyraspberry
Hi all,

After looking through the pureBasic demo and documents I am very impressed. I have been a long term user of BB4W (BBC BASIC for Windows) and although up to now has helped me develop my programming I think has serious limitations to developing Windows applications, for example, subclassing, using callbacks, lack of multithreading support, it also misses some windows messages and it is difficult to respond to WM_NOTIFY messages and WM_PAINT messages without having to resort to assembly language. Although it does excel in small code footprint and speed (for an interpreter).

If anyone has the time would you be able to answer the following?

1. I am very interested in being able to build x64 bit applications. I have been able to examine a disassembly of the code (from one of the example programs) and it seems(!) to use the rax register and the interger range seems to be quad. So far amazing. Is it possible to code inline x64 bit instructions? Or would I have to directly write the bytecode into an area of memory?

2. I've looked through some of the 3D examples - great stuff. Does it provide DirectX11 support and HLSL? - sorry this may be a very simple question to answer and I have probably just missed this.

3. The ability to multithread pureBASIC is a fantastic attribite... multithreading in BB4W is nigh impossible and I had to hand code all my threads in ASM...which was severly limiting due to my failings as a coder! I have some very speciallise ASM functions/threads which I would like to try and port to pureBASIC .. could I call ASM with CreateThread?

4. And related to 3. I suppose it is easy to use the windows API after importing them (have have briefly read the intro)...


Anyway, I suspect I may have already bought a copy before anyone replied to this.... I am very excited about the possibilities and am just disappointed I haven't seen pureBasic up to now.

Michael :)

Re: Thinking of buying PureBasic but have some questions :)

Posted: Fri Sep 28, 2012 11:22 am
by Josh
tastyraspberry wrote:4. And related to 3. I suppose it is easy to use the windows API after importing them (have have briefly read the intro)...
hmmmmmm .....

From which intro are you speaking? The most windows API's you don't need to import, they are integrated in PB.

Re: Thinking of buying PureBasic but have some questions :)

Posted: Fri Sep 28, 2012 12:55 pm
by tastyraspberry
Ok. If most of the API functions are fully integrated thats fine. Do you have any idea about the other points?

Re: Thinking of buying PureBasic but have some questions :)

Posted: Fri Sep 28, 2012 3:14 pm
by IdeasVacuum
You don't actually mention the type of app you wish to make, but in most cases, PB won't let you down.

Link to the online Help: http://www.purebasic.com/documentation/index.html

Re: Thinking of buying PureBasic but have some questions :)

Posted: Fri Sep 28, 2012 4:14 pm
by Tenaja
1. Yes. PB is not an interpreter, so there is no bytecode. However, you can do asm, if you wish.

2. I don't know; not into graphics.

3. You can call any thread-safe procedure with CreateThread. This is from the help file:
PureBasic has a special compiler setting to create thread-safe executables. (/THREAD command-line switch or "create thread-safe executable" in the IDE compiler options). Without this mode, certain functions (and also the string access) are faster, but not save to use in threads. It is still possible to create threads without this mode but it is not recommended, as even something simple like a local string access can be dangerous and needs to be protected. Enabling this option makes these things save inside threads, but comes at the price of some speed. The decision on whether or not to use threads should therefore done with care, and the threadmode should only be used when there is a real need for it.

4. As others have said, there is no import; it is just like using any other PB function call with the exception of adding an underscore to the name. So instead of calling MessageBox(), you would call MessageBox_(). (Although that specific command is redundant to PB, since we have our own cross-platform MessageRequester()

If you are coming off of an interpreter, chances are you will be thrilled with PB.

Re: Thinking of buying PureBasic but have some questions :)

Posted: Fri Sep 28, 2012 6:23 pm
by tastyraspberry
Thanks to all who have replied. I will play with the demo version a bit more and see what I can come up with. As to what applications I want to write, well that is a hard questions really. They are mostly tinkering programs as I am an amatuer and hobbyist programmer. There is no one project that I would like to do.

Again, thanks all for your replies.

Maybe I'll see you mroe often on the forums!

Michael

Re: Thinking of buying PureBasic but have some questions :)

Posted: Fri Sep 28, 2012 8:52 pm
by tastyraspberry
Well, my first speed test of has come back as 43 times faster than the bb4w interpreter... :)

Code: Select all

OpenConsole()

t = ElapsedMilliseconds()             
  
ff = 12000
ff = (ff/4) * 14
Dim f.i(ff)
For i = 0 To ArraySize(f()) 
    f(i) = 2000  
Next
a = 10000
e = 0
For c = ff To 14 Step -14
  d = 0
    For b = c To 1 Step -1
          d = d * b
          g = b * 2 - 1
          d = d + f(b) * a
          f(b) = d % g
          d = d/g
    Next
  Print(Right("000"+Str(e + d / a),4))
  e = d % a
Next
tt = ElapsedMilliseconds()             
PrintN("")
PrintN("Tick count = " + Str((tt-t)/100))
PrintN("Press enter to exit.")
Input()
Is there a way to fill out an array with a default value without looping through each element?

Michael

Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 5:34 am
by leonhardt
tastyraspberry wrote:Well, my first speed test of has come back as 43 times faster than the bb4w interpreter... :)

Code: Select all

OpenConsole()

t = ElapsedMilliseconds()             
  
ff = 12000
ff = (ff/4) * 14
Dim f.i(ff)
For i = 0 To ArraySize(f()) 
    f(i) = 2000  
Next
a = 10000
e = 0
For c = ff To 14 Step -14
  d = 0
    For b = c To 1 Step -1
          d = d * b
          g = b * 2 - 1
          d = d + f(b) * a
          f(b) = d % g
          d = d/g
    Next
  Print(Right("000"+Str(e + d / a),4))
  e = d % a
Next
tt = ElapsedMilliseconds()             
PrintN("")
PrintN("Tick count = " + Str((tt-t)/100))
PrintN("Press enter to exit.")
Input()
Is there a way to fill out an array with a default value without looping through each element?

Michael
use datasection:

Code: Select all

DataSection
  ptrMyArray:
  Data.b $12,$13,$14
EndDataSection

Dim MyArray.b(2)
MoveMemory(?ptrMyArray,@MyArray(),(ArraySize(MyArray())+1)*SizeOf(Byte))
For i=0 To 2
  Debug MyArray(i)
Next



Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 5:39 am
by leonhardt
But I really like this way:(in Delphi)

Code: Select all

   var
    MyArray:array[0..2]of byte =(0,1,2) ;

more efficient,without extra operation(MoveMemory).

Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 8:05 am
by Danilo
tastyraspberry wrote:Is there a way to fill out an array with a default value without looping through each element?
FillMemory if you use Byte, Word or Long types only. Integer and Quad are missing for FillMemory.

Code: Select all

Dim f.l(100)
FillMemory( @f(), (ArraySize(f())+1) * SizeOf(Long), 2000, #PB_Long )

For i = 0 To 100
    Debug f(i)
Next i

Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 10:51 am
by tastyraspberry
Ok, Interesting thanks. I've noticed there are no whole array operators.for instance in some other languages

Code: Select all

Myarray()=2; fills entire array
Myarray()/=2;   divides every element by two
[code]
I found the this quite useful but admittedly never really worried how it was being done under the hood.

Michael

Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 12:53 pm
by Danilo
tastyraspberry wrote:I found the this quite useful but admittedly never really worried how it was being done under the hood.
Could be done with operator overloading in C++. In PureBasic you have to write some functions for that specific array type.
In C++ you would need to write the same functions, but as operator functions.

Code: Select all

Procedure fillArray(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    For i = 0 To size
        arr(i) = value
    Next
EndProcedure

Procedure divArray(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    For i = 0 To size
        arr(i) / value
    Next
EndProcedure

Procedure addArray(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    For i = 0 To size
        arr(i) + value
    Next
EndProcedure

Procedure subArray(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    For i = 0 To size
        arr(i) - value
    Next
EndProcedure

Procedure mulArray(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    For i = 0 To size
        arr(i) * value
    Next
EndProcedure




Macro out()
    For i = 0 To ArraySize(MyArray()) : Debug MyArray(i) : Next
    Debug "-----------------------------------"
EndMacro

Dim MyArray.i(10)

fillArray(MyArray(), 2000) : out()
divArray(MyArray(), 4)     : out()
divArray(MyArray(), 5)     : out()
addArray(MyArray(), 100)   : out()
subArray(MyArray(), 25)    : out()
mulArray(MyArray(), 4)     : out()
For other array types you have to write other functions.

If the arrays are of the same dimension and of basic types, you could use template programming using macros.
The following functions work with arrays of different PureBasic types, but you have to give the type to the functions/macros:

Code: Select all

Macro fillArray(_arr_,_type_,_value_)
    CompilerIf Defined(_fillArray_#_type_,#PB_Procedure)=0
        Procedure _fillArray_#_type_(Array arr._type_(1), value._type_)
            Protected i, size = ArraySize(arr())
            For i = 0 To size
                arr(i) = value
            Next
        EndProcedure
    CompilerEndIf
    _fillArray_#_type_(_arr_, _value_)
EndMacro

Macro divArray(_arr_,_type_,_value_)
    CompilerIf Defined(_divArray_#_type_,#PB_Procedure)=0
        Procedure _divArray_#_type_(Array arr._type_(1), value._type_)
            Protected i, size = ArraySize(arr())
            For i = 0 To size
                arr(i) / value
            Next
        EndProcedure
    CompilerEndIf
    _divArray_#_type_(_arr_, _value_)
EndMacro

Macro addArray(_arr_,_type_,_value_)
    CompilerIf Defined(_addArray_#_type_,#PB_Procedure)=0
        Procedure _addArray_#_type_(Array arr._type_(1), value._type_)
            Protected i, size = ArraySize(arr())
            For i = 0 To size
                arr(i) + value
            Next
        EndProcedure
    CompilerEndIf
    _addArray_#_type_(_arr_, _value_)
EndMacro

Macro subArray(_arr_,_type_,_value_)
    CompilerIf Defined(_subArray_#_type_,#PB_Procedure)=0
        Procedure _subArray_#_type_(Array arr._type_(1), value._type_)
            Protected i, size = ArraySize(arr())
            For i = 0 To size
                arr(i) - value
            Next
        EndProcedure
    CompilerEndIf
    _subArray_#_type_(_arr_, _value_)
EndMacro

Macro mulArray(_arr_,_type_,_value_)
    CompilerIf Defined(_mulArray_#_type_,#PB_Procedure)=0
        Procedure _mulArray_#_type_(Array arr._type_(1), value._type_)
            Protected i, size = ArraySize(arr())
            For i = 0 To size
                arr(i) * value
            Next
        EndProcedure
    CompilerEndIf
    _mulArray_#_type_(_arr_, _value_)
EndMacro




Macro out(_arr_)
    For i = 0 To ArraySize(_arr_()) : Debug _arr_(i) : Next
    Debug "-----------------------------------"
EndMacro

Dim MyArray.i(5)

fillArray(MyArray(), i, 2000) : out(MyArray)
divArray(MyArray(), i, 4)     : out(MyArray)
divArray(MyArray(), i, 5)     : out(MyArray)
addArray(MyArray(), i, 100)   : out(MyArray)
subArray(MyArray(), i, 25)    : out(MyArray)
mulArray(MyArray(), i, 4)     : out(MyArray)

Debug "double array"

Dim dblArr.d(5)

fillArray(dblArr(), d, 1.234567) : out(dblArr)
addArray(dblArr(), d, 10.0)      : out(dblArr)
divArray(dblArr(), d, 4.0)       : out(dblArr)
subArray(dblArr(), d, 1.0)       : out(dblArr)
mulArray(dblArr(), d, 10.0)      : out(dblArr)

Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 1:53 pm
by IdeasVacuum
I like the For Next loops for their elegance but if it's speed you are after, try the others (Repeat, While)

Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 2:04 pm
by Fred
The difference is negligible so For/Next should be always used where it stands:

Code: Select all

Procedure fillArray(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    For i = 0 To size
        arr(i) = value
    Next
EndProcedure

Procedure divArray(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    For i = 0 To size
        arr(i) / value
    Next
  EndProcedure
  
  Procedure divArrayRepeat(Array arr.i(1), value)
    Protected i, size = ArraySize(arr())
    Repeat 
      arr(i) / value
      i + 1
    Until i > size
EndProcedure





Macro out()
    For i = 0 To ArraySize(MyArray()) : Debug MyArray(i) : Next
    Debug "-----------------------------------"
EndMacro

Dim MyArray.i(100000000)

fillArray(MyArray(), 2000) : out()

s = ElapsedMilliseconds()
divArray(MyArray(), 4)     : out()

MessageRequester("",Str(ElapsedMilliseconds()-s))


fillArray(MyArray(), 2000) : out()

s = ElapsedMilliseconds()
divArrayRepeat(MyArray(), 4)     : out()

MessageRequester("",Str(ElapsedMilliseconds()-s))

Re: Thinking of buying PureBasic but have some questions :)

Posted: Sat Sep 29, 2012 2:05 pm
by tastyraspberry
@danilo
Thanks. Good explanation. I like the functions/procedure way of doing it. Haven't quite got my head around the macro way yet. I'm sitting here tinkering away today so I am sure I can work it out later.