[Gambas-user] [Fwd: Gambas3 Pointers example] signal #6

Demosthenes Koptsis demosthenesk at ...626...
Mon Jan 10 22:05:55 CET 2011


On Mon, 2011-01-10 at 21:58 +0200, Jussi Lahtinen wrote:
> Oh, I forgot to mention, that when you do "Free(pPointer)", Gambas doesn't
> occupy that memory address for you anymore.
> And therefore some other process can write something to it, and result is
> not necessarily human readable.
> 
> Jussi
> 

Ok, understood.
But i have put the contents of memory address to a variable.

sWorkingDirectory = Str@(pFunc)

if i free pFunc why variable sWorkingDirectory is affected?

if this is happend i must know it, so to use variables before free any
pointer.


> 
> On Mon, Jan 10, 2011 at 21:54, Jussi Lahtinen <jussi.lahtinen at ...626...>wrote:
> 
> >
> >
> >> first print gives the correct output
> >> /home/user/Documents/Development/Gambas3/Pointers7
> >>
> >> and the second after Free(pFunc) gives this
> >> �s&^@^@^@^@^@^@^@^@^@ocuments/Development/Gambas3/Pointers7
> >>
> >
> >
> > This has something to do how strings are handled in Gambas, I don't think
> > this is bug.
> >
> > Some lines of simplified example code and explanation:
> >
> > Dim pPointer As Pointer
> > Dim hMemory As Stream
> > Dim s As String
> >
> > pPointer = Alloc(4) ' Alloc for four characters, last one means 'end of
> > string'.
> > hMemory = Memory pPointer For Write
> > Write #hMemory, Asc("a") As Byte
> > Write #hMemory, Asc("b") As Byte
> > Write #hMemory, Asc("c") As Byte
> > Write #hMemory, Asc("\0") As Byte
> >
> > s = Str@(pPointer) ' This associates address to variable. Ie, in address
> > pPointer is content of this string.
> >
> > Print s ' This will print out; "abc"
> >
> > Seek #hMemory, 0
> > Write #hMemory, Asc("x") As Byte ' These two lines will access to address
> > pPointer and change first character in there.
> >
> > Print s ' Therefore string changes to "xbc". Variable 's' is just
> > representation of content in some (in this case pPointer) address.
> >

Yes this is happens!

This is behaved like s variable acts as a pointer to pPointer.
As it beahaves seems s is linked with pPointer.
I think that s should not point to pPointer but copy its value to s
variable.

Result = String@ ( Pointer AS Pointer )

Result i think is a value, so this value is assigned to s var.
After assignation s has a value and should not change it if i Free a
pointer. 

If i write to pPointer or Free it, the s var is placed in other adress
normally in RAM.

As i understand the case,

pPointer = Alloc(4) allocate a memory address1
Dim s as string     allocate a memory address2

if i use 
s=Str@(pPointer)

this means
address1=adress2 ?

s holds a value, Str@(pPointer) returns a value not its address and
should not be linked s by addresses as pointers

Am i wrong?


For now i will upgrade Gambas to latest revision and try again.
> >
> >
> >>
> >> b) if i use Free(pBuf)
> >> i get signal #6
> >>
> >
> > I don't think this should happen... Benoit?
> >
> >
> >
> >
> >> here i get correct results
> >> but if i use Free(pFunc) i get signal #11
> >>
> >
> > This shouldn't happen, it is bug.
> > However I couldn't reproduce it with Gambas 3 rev 3451,
> > but I got signal 6 from it.
> >
> >
> > Jussi
> >
> >
> ------------------------------------------------------------------------------
> 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





More information about the User mailing list