Revision history for TutPterDataType


Revision [22021]

Last edited on 2017-11-21 01:12:04 by JeffMarshall [fix page link name case]
Additions:
On a 32-bit system, the pointer data type is 4 bytes (8 bytes on a 64-bit system). FreeBasic uses pointers for a number of functions such as [[KeyPgImagecreate|ImageCreate]], and pointers are used heavily in external libraries such as the Windows API. Pointers are also quite fast, since the compiler can directly access the memory location that a pointer points to. A proper understanding of pointers is essential to effective programming in FreeBasic.
Deletions:
On a 32-bit system, the pointer data type is 4 bytes (8 bytes on a 64-bit system). FreeBasic uses pointers for a number of functions such as [[KeyPgImageCreate|ImageCreate]], and pointers are used heavily in external libraries such as the Windows API. Pointers are also quite fast, since the compiler can directly access the memory location that a pointer points to. A proper understanding of pointers is essential to effective programming in FreeBasic.


Revision [21461]

Edited on 2016-05-12 06:02:58 by fxm [Formatting]
Additions:
Return number^pwr
Dim As Integer el1, el2
Static cnt As Integer
'Get the call count and items passed
cnt += 1
'Get the values, must cast to integer ptr
el1 = *(CPtr(Integer Ptr, e1))
el2 = *(CPtr(Integer Ptr, e2))
Print "Qsort called";cnt;" time(s) with";el1;" and";el2;"."
'Compare the values
If el1 < el2 Then
Return -1
ElseIf el1 > el2 Then
Return 1
Else
Return 0
End If
myMemArray[i] = CAllocate(10, SizeOf(Integer))
For j As Integer = 0 To 9
myMemArray[i][j] = Int(Rnd * 10)
Next
Deallocate myMemArray[i]
Deletions:
Return number^pwr
Dim As Integer el1, el2
Static cnt As Integer
'Get the call count and items passed
cnt += 1
'Get the values, must cast to integer ptr
el1 = *(CPtr(Integer Ptr, e1))
el2 = *(CPtr(Integer Ptr, e2))
Print "Qsort called";cnt;" time(s) with";el1;" and";el2;"."
'Compare the values
If el1 < el2 Then
Return -1
ElseIf el1 > el2 Then
Return 1
Else
Return 0
End If
myMemArray[i] = CAllocate(10, SizeOf(Integer))
For j As Integer = 0 To 9
myMemArray[i][j] = Int(Rnd * 10)
Next
Deallocate myMemArray[i]


Revision [21457]

Edited on 2016-05-11 16:26:37 by fxm [Update for 64bit port]
Additions:
On a 32-bit system, the pointer data type is 4 bytes (8 bytes on a 64-bit system). FreeBasic uses pointers for a number of functions such as [[KeyPgImageCreate|ImageCreate]], and pointers are used heavily in external libraries such as the Windows API. Pointers are also quite fast, since the compiler can directly access the memory location that a pointer points to. A proper understanding of pointers is essential to effective programming in FreeBasic.
Deletions:
On a 32-bit system, the pointer data type is 4 bytes (8 bytes on a 64-bit system). FreeBasic uses pointers for a number of functions such as ImageCreate, and pointers are used heavily in external libraries such as the Windows API. Pointers are also quite fast, since the compiler can directly access the memory location that a pointer points to. A proper understanding of pointers is essential to effective programming in FreeBasic.


Revision [21456]

Edited on 2016-05-11 16:13:20 by fxm [Update for 64bit port]
Additions:
On a 32-bit system, the pointer data type is 4 bytes (8 bytes on a 64-bit system). FreeBasic uses pointers for a number of functions such as ImageCreate, and pointers are used heavily in external libraries such as the Windows API. Pointers are also quite fast, since the compiler can directly access the memory location that a pointer points to. A proper understanding of pointers is essential to effective programming in FreeBasic.
When using the Allocate function you must specify the storage size based on the data type using the equation number_of_elements * Sizeof(datatype). To allocate space for 10 integers your code would look like this: myPointer = Allocate(10 * Sizeof(Integer)). An integer is 4/8 bytes (on 32/64 bit systems) so allocating 10 integers will set aside 40/80 bytes of memory (on 32/64bit systems). Allocate does not clear the memory segment, so any data in the segment will be random, meaningless data until it is initialized.
Since the compiler knows that the pointer is an Integer pointer, adding 1 to the pointer reference will actually increment the address contained in myPtr by 4/8 (on 32/64bit systems), the size of an Integer. This is why using typed pointers is preferable over untyped pointers. The compiler does much of the work for you in accessing the data in the memory segment.
Return number^pwr
The qsort, function contained within the C Runtime Library sorts the elements of an array using a callback function to determine the sort order. The prototype for the qsort function is contained in crt/stdlib.bi:
declare sub qsort (byval as any ptr, byval as size_t, byval as size_t, byval as function(byval as any ptr, byval as any ptr) as long)
Declare Function QCompare CDecl (ByVal e1 As Any Ptr, ByVal e2 As Any Ptr) As Long
Function QCompare CDecl (ByVal e1 As Any Ptr, ByVal e2 As Any Ptr) As Long
Dim As Integer el1, el2
Static cnt As Integer
'Get the call count and items passed
cnt += 1
'Get the values, must cast to integer ptr
el1 = *(CPtr(Integer Ptr, e1))
el2 = *(CPtr(Integer Ptr, e2))
Print "Qsort called";cnt;" time(s) with";el1;" and";el2;"."
'Compare the values
If el1 < el2 Then
Return -1
ElseIf el1 > el2 Then
Return 1
Else
Return 0
End If
#include "crt/stdlib.bi"
qsort @myArray(0), 10, SizeOf(Integer), @QCompare
For i As Integer = 0 To 9
myMemArray[i] = CAllocate(10, SizeOf(Integer))
For i As Integer = 0 To 9
For j As Integer = 0 To 9
myMemArray[i][j] = Int(Rnd * 10)
Next
For i As Integer = 0 To 9
Deallocate myMemArray[i]
Deletions:
On a 32-bit system, the pointer data type is 4 bytes. FreeBasic uses pointers for a number of functions such as ImageCreate, and pointers are used heavily in external libraries such as the Windows API. Pointers are also quite fast, since the compiler can directly access the memory location that a pointer points to. A proper understanding of pointers is essential to effective programming in FreeBasic.
When using the Allocate function you must specify the storage size based on the data type using the equation number_of_elements * Sizeof(datatype). To allocate space for 10 integers your code would look like this: myPointer = Allocate(10 * Sizeof(Integer)). An integer is 4 bytes so allocating 10 integers will set aside 40 bytes of memory. Allocate does not clear the memory segment, so any data in the segment will be random, meaningless data until it is initialized.
Since the compiler knows that the pointer is an Integer pointer, adding 1 to the pointer reference will actually increment the address contained in myPtr by 4, the size of an Integer. This is why using typed pointers is preferable over untyped pointers. The compiler does much of the work for you in accessing the data in the memory segment.
Return number^pwr
The qsort, function contained within the C Runtime Library sorts the elements of an array using a callback function to determine the sort order. The prototype for the qsort function is contained in stdlib.bi:
declare sub qsort cdecl alias "qsort" (byval as any ptr, byval as size_t, byval as size_t, byval as function cdecl(byval as any ptr, byval as any ptr) as integer)
Declare Function QCompare Cdecl (Byval e1 As Any Ptr, Byval e2 As Any Ptr) As Integer
Function QCompare Cdecl (Byval e1 As Any Ptr, _
Byval e2 As Any Ptr) As Integer
Dim As Integer el1, el2
Static cnt As Integer
'Get the call count and items passed
cnt += 1
'Get the values, must cast to integer ptr
el1 = *(Cptr(Integer Ptr, e1))
el2 = *(Cptr(Integer Ptr, e2))
Print "Qsort called";cnt;" time(s) with";el1;" and";el2;"."
'Compare the values
If el1 < el2 Then
Return -1
Elseif el1 > el2 Then
Return 1
Else
Return 0
End If
qsort @myArray(0), 10, Sizeof(Integer), @QCompare
For i = 0 To 9
myMemArray[i] = Callocate(10, Sizeof(Integer))
For i = 0 To 9
For j = 0 To 9
myMemArray[i][j] = Int(Rnd * 10)
For i = 0 To 9
Deallocate myMemArray[i]


Revision [20704]

Edited on 2016-02-10 16:15:36 by DkLwikki [Update link format]
Additions:
//Written by [[WikiRick|rdc]]//
FreeBasic has the following [[CatPgOpPoint|pointer operators]].
FreeBasic also has a number of [[CatPgMemory|memory functions]] that are used with pointers.
~- [[KeyPgCptr|Cptr]] Converts expression to a data_type pointer. Expression can be another pointer or an integer.
~- [[KeyPgPeek|Peek]] Returns the contents of memory location pointer to by pointer. Data_type specifies the type of expected data.
~- [[KeyPgPoke|Poke]] Puts the value of expression into the memory location pointed to by pointer. The data_type specifies the type of data being placed into the memory location.
~- [[KeyPgSadd|Sadd]] Returns the location in memory where the string data in a dynamic string is located.
~- [[KeyPgOpStrptr|Strptr]] The same as Sadd.
~- [[KeyPgOpProcptr|Procptr]] Returns the address of a function. This works the same way as the addressof operator @.
~- [[KeyPgOpVarptr|Varptr]] This function works the same way as the addressof operator @.
Return 0
Deletions:
//Written by [[WikiRick rdc]]//
FreeBasic has the following [[CatPgOpPoint pointer operators]].
FreeBasic also has a number of [[CatPgMemory memory functions]] that are used with pointers.
~- [[KeyPgCptr Cptr]] Converts expression to a data_type pointer. Expression can be another pointer or an integer.
~- [[KeyPgPeek Peek]] Returns the contents of memory location pointer to by pointer. Data_type specifies the type of expected data.
~- [[KeyPgPoke Poke]] Puts the value of expression into the memory location pointed to by pointer. The data_type specifies the type of data being placed into the memory location.
~- [[KeyPgSadd Sadd]] Returns the location in memory where the string data in a dynamic string is located.
~- [[KeyPgOpStrptr Strptr]] The same as Sadd.
~- [[KeyPgOpProcptr Procptr]] Returns the address of a function. This works the same way as the addressof operator @.
~- [[KeyPgOpVarptr Varptr]] This function works the same way as the addressof operator @.
Return 0


Revision [16967]

Edited on 2013-10-05 13:41:37 by FxMwikki [Typo]
Additions:
~- [[KeyPgPeek Peek]] Returns the contents of memory location pointer to by pointer. Data_type specifies the type of expected data.
Deletions:
~- [[KeyPgPeek Peek]] Peek returns the contents of memory location pointer to by pointer. Data_type specifies the type of expected data.


Revision [16908]

Edited on 2013-08-05 01:57:00 by FxMwikki [Corrected the bad link to "Pointer Operators" (CatPgOpPoint instead of CatPgOperators previously)]
Additions:
FreeBasic has the following [[CatPgOpPoint pointer operators]].
Deletions:
FreeBasic has the following [[CatPgOperators pointer operators]].


Revision [10412]

The oldest known version of this page was created on 2007-07-31 11:46:27 by JeffMarshall [Corrected the bad link to "Pointer Operators" (CatPgOpPoint instead of CatPgOperators previously)]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode