On Mon, 2011-01-17 at 13:33 +0100, Benoît Minisini wrote: > > sorry my wrong expression. > > > > No problem. > > Another point: at the moment, Alloc() and Free() are not the equivalent of > malloc() and free() in C. So you cannot use Free() to free a memory > allocation > returned as a pointer by a C function. You must use the free() function > located in the C library directly. > > Regards, >
About that, The next example uses free() function of C to free a pointer. Example1 ------------ ' Gambas module file 'char *get_current_dir_name(void); Extern get_current_dir_name() As Pointer In "libc:6" 'void free(void *ptr); Extern free_ptr(ptr As Pointer) In "libc:6" Exec "free" Public Sub Main() Dim pFunc As Pointer Dim sWorkingDirectory As String 'get_current_dir_name pFunc = get_current_dir_name() Print pFunc sWorkingDirectory = Str@(pFunc) Print sWorkingDirectory free_ptr(pFunc) pFunc = 0 End ------------ free_ptr(pFunc) is the free() function of C and here frees a pointer which was allocated internal by get_current_dir_name(). But free() function of C, cannot free a pointer allocated by Alloc() of Gambas. May be this is obvious or expected but is good to say it. Example2 -------------- ' Gambas module file 'void free(void *ptr); Extern free_ptr(ptr As Pointer) In "libc:6" Exec "free" Public Sub Main() Dim pPointer As Pointer pPointer = Alloc(4) free_ptr(pPointer) End example2 gives signal #6. -- Regards, Demosthenes ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user