I have a big memory problem since more days thant I can't resolve, and with my friends also.
I have a my C function called "MyClass::TCP_Ping()" for ping a machine, this work, but when I call this function, my previous string variables and other was erased :-/
For test if isn't my "TCP runtime / driver and other.." I just test this :
Code: Select all
MyClass::TCP_Ping()
{
int titi;
char * blabla;
char * toto;
toto = (char*)"blabal";
titi= (char*)"blabal";
toto = (char*) "blabal";
blabla= (char*)"blabal";
return 0;
/* .........
....
.... */
}
So, I use "allocate()" for allocate my previous string variables of FreeBasic, same problem
I finish to write a C function for allocate my variables with ZString ptr :
Code: Select all
char * Allocate_String (char *text)
{
size_t sizz = (size_t) strlen(text);
char *value = (char *) malloc (sizz + 1);
value[sizz ] = '\0';
return (char *) memcpy (value, text, sizz );
}
On freebasic, I have this :
Code: Select all
'' I use my Allocate_String function, and he return a pointer address
dim MyIP as ZString ptr = Allocate_String("192.168.1.10")
dim MyClassInstance as MyPingFunction
dim results as integer
'' I cal my C function
print "Pinging " & *MyIP & " machine ... - - Variable pointer:" & MyIP
results = MyClassInstance::TCP_Ping(MyIP)
if results = 0 then
print "Machine:" & *MyIP & " is here! - - Variable pointer:" & MyIP
else
print "Ho, I not found, sorry - - Variable pointer:" & MyIP
end if
Code: Select all
Pinging 192.168.1.10 machine ... - - Variable pointer:19212348920
Machine: is here
I proceed to multiple tests, same problem with integer variable.....My C function erase my FreeBasic variables :-(
But.. {m, c}alloc in my tcp_ping function, check if there are used memory block???
Thank