[Gambas-user] Tests against pointers in Gambas3

Benoît Minisini gambas at ...1...
Sat Jan 15 02:12:04 CET 2011


> Hi,
> 
> i study the cases of pointers and i found at this page
> http://www.yolinux.com/TUTORIALS/C++MemoryCorruptionAndMemoryLeaks.html
> 
> cases of program crashes from bad usage of pointers.
> 
> i made a test for
> Attempting to write to memory already freed.
> 
> ---------------------------
> ' Gambas module file
> 
> Public Sub Main()
> 
> Dim pPointer As Pointer
> Dim hMemory As Stream
> 
> pPointer = Alloc(SizeOf(gb.Integer))
> hMemory = Memory pPointer For Read Write
> 
> Print pPointer
> 
> Free(pPointer)
> 
> Write #hMemory, 10 As Integer
> 
> Print pPointer
> Print Int@(pPointer)
> Print pPointer
> 
> End
> ---------------------------
> 
> in this example i free the pointer and then try to write to it.
> The result is that i can write and read normally after Free(pPointer)
> 
> Is this ok?

Yes.

Freed memory is not made forbidden automatically (it will be too slow). The C 
library decides when freed memory is given back to the system.

I didn't think that Gambas will make somebody learn C and system programming 
;-)

Regards,

-- 
Benoît Minisini





More information about the User mailing list