[Gambas-user] [Fwd: Gambas3 Pointers example]

Demosthenes Koptsis demosthenesk at ...626...
Sun Jan 9 11:12:08 CET 2011


Here is another question-case.

i Alloc 12 bytes.
i set in memory an integer 4 bytes
then i set in memory a float 8 bytes.

i can read the memory stream with READ, ok!

How can i to this with Integer@() and Float@() functions?
How can i move inside memory and use Integer@() and Float@()

example:
--------------------------
' Gambas module file

Public Sub Main()

Dim pPointer As Pointer
Dim hMemory As Stream
Dim iA As Integer
Dim fA As Float

pPointer = Alloc(12)
hMemory = Memory pPointer For Read Write

Print "Stream pointer potition at:"; Seek(hMemory)
Print "Writing to memory stream a 4 byte integer"
Write #hMemory, 10 As Integer
Print "Stream pointer potition at:"; Seek(hMemory)

Print "Writing to memory stream a 8 byte float"
Write #hMemory, 4.2 As Float
Print "Stream pointer potition at:"; Seek(hMemory)

Print "Set stream potition at the begining"
Seek #hMemory, 0

Print "Stream pointer potition at:"; Seek(hMemory)

Print "Read the integer"
iA = Read #hMemory As Integer
Print iA
Print "Stream pointer potition at:"; Seek(hMemory)

Print "Read the float"
fA = Read #hMemory As Float
Print fA
Print "Stream pointer potition at:"; Seek(hMemory)

Print "\nRead the pointer"
Print "Integer read:"; Integer@(pPointer)
Print "Float read:"; Float@(pPointer)

Free(pPointer)

End
--------------------------

output:
--------------------------
Stream pointer potition at:0
Writing to memory stream a 4 byte integer
Stream pointer potition at:4
Writing to memory stream a 8 byte float
Stream pointer potition at:12
Set stream potition at the beginning
Stream pointer potition at:0
Read the integer
10
Stream pointer potition at:4
Read the float
4.2
Stream pointer potition at:12

Read the pointer
Integer read:10
Float read:-9.25596411572894E+61
--------------------------

On Sat, 2011-01-08 at 23:07 +0200, Demosthenes Koptsis wrote:
> On Sat, 2011-01-08 at 22:07 +0200, Jussi Lahtinen wrote:
> > > hMemory = Memory pPointer For Read Write
> > > Write #hMemory, 10 As Integer
> > >
> > > is there any other way that i did not notice?
> 
> thanks Jussi.
> i just wondered if there is something else than write instruction for
> writing into a pointer.
> 
> But as i see a pointer is manipulated by stream read/write instructions.
> 
> Never mind just exploring Gambas3 and docs.
> 
> > >
> > 
> > I'm not sure I understand what do you mean/need...
> > Documentation gives two options;
> > 
> > *WRITE* [ *#* *Stream* *,* ] *Expression* *AS* *Datatype*
> > *WRITE* [ *#* *Stream* *,* ] *String* [ *,* *Length* ]
> > 
> > But I personally use streams just for reading data from external functions.
> > So, in other words, my third option is to pass pointer to external function
> > and let it write to stream.
> > 
> > You can see example from my GambasTester project (attached), just search
> > "modf".
> > Here is C++ reference:
> > http://www.cplusplus.com/reference/clibrary/cmath/modf/
> > 
> > Jussi
> > P.S. Test will not pass right now, because some new functions (possibly
> > obsolete) are missing from test.
> > ------------------------------------------------------------------------------
> > Gaining the trust of online customers is vital for the success of any company
> > that requires sensitive data to be transmitted over the Web.   Learn how to 
> > best implement a security strategy that keeps consumers' information secure 
> > and instills the confidence they need to proceed with transactions.
> > http://p.sf.net/sfu/oracle-sfdevnl 
> > _______________________________________________ Gambas-user mailing list Gambas-user at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
> 

-- 
Regards,
Demosthenes Koptsis.





More information about the User mailing list