Big memory problem. FreeBasic to C and C to FreeBasic

DOS specific questions.
Post Reply
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Big memory problem. FreeBasic to C and C to FreeBasic

Post by Cpcdos »

Hi,
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;
	/* .........
	....
	.... */
}
Just this erase my FreeBasic variables! :-/ It's strange?

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 );
}
This work, I can store and display my ZString variables from FreeBasic / C , so this function is OK!

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
He return :

Code: Select all

Pinging 192.168.1.10 machine ...   - - Variable pointer:19212348920
Machine:  is here
My MyIP variable pointer content is "0" but.... WHAT ??

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
fxm
Moderator
Posts: 12162
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Big memory problem. FreeBasic to C and C to FreeBasic

Post by fxm »

I understand that I understand nothing, but as no one answers!

There seems to be an inconsistency between the definition of the procedure:
MyClass::TCP_Ping()
and the calling syntax:
results = MyClassInstance::TCP_Ping(MyIP)
(the return result and the parameter to pass?)
caseih
Posts: 2158
Joined: Feb 26, 2007 5:32

Re: Big memory problem. FreeBasic to C and C to FreeBasic

Post by caseih »

Post some self-contained, runnable code and I'm sure you'll get a few people willing to try to figure out what's wrong. As it stands there's simply not a lot we can say. You say you have big memory problems but you don't say what that means. You hint at memory corruption but I can't be sure.

Post a complete code example and I'm will to take a look. Though I may not be much help because I don't use DOS at all. But if there is a memory corruption problem it may show up on other platforms too.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: Big memory problem. FreeBasic to C and C to FreeBasic

Post by Cpcdos »

Excuse me for my late response (holiday)

My problem was resolved after have put a namespace in my C file, where there are my function.. Yes is it strange, but this work
But thank you all!

If someone can explain memory influence to use namespace ?

http://stackoverflow.com/questions/1452 ... d-practice & http://stackoverflow.com/questions/1888 ... -namespace
Post Reply