Hi,
I have some routines writed in C (Borland C++). Old exe files from 2000 year not run on Windows 8.1 64bit. I mean also on W7 64 bit.
Is big problem compile it for running on W7 W8, W10 ?
Also, how can it implement as part of Alaska Xbase ? Must be dll file ?
In Turbo C or Borland C+ was generating EXE , and LIB, but DLL no. Some newer compiler has also DLL ?
My routines is not complicated but I need it very fast.
I will examine reprogramming it in Alaska Xbase, but I mean it will be slower than C.
Viktor
C language and Xbase
Re: C language and Xbase
Xbase++ has an API for linking C code into and Xbase++ DLL or EXE.
In fact, eXpress++ has a tiny fragment of C code that is used by the Dot-Prompt Interpreter (DC_Dot())
Look at \exp20\source\dclipc\dcdeftra.c and \exp20\source\dclipc\dckey.c.
However, if you are familiar with what the Turbo C code does, then it would probably be best to rewrite it in Xbase++. Xbase++ is much faster than you think when only doing calculations. It's performance is more limited by the access to databases and the Windows GUI interface.
In fact, eXpress++ has a tiny fragment of C code that is used by the Dot-Prompt Interpreter (DC_Dot())
Look at \exp20\source\dclipc\dcdeftra.c and \exp20\source\dclipc\dckey.c.
However, if you are familiar with what the Turbo C code does, then it would probably be best to rewrite it in Xbase++. Xbase++ is much faster than you think when only doing calculations. It's performance is more limited by the access to databases and the Windows GUI interface.
The eXpress train is coming - and it has more cars.
Re: C language and Xbase
thanks for info.
In C utility I have many string manipulation (coding, decoding, lempel ziv algoritm, code page converting..) and file manipulations (read, write from/to ascii file).
OK, first I test it in Xbase , file access will use DC_TxtOpen,TxtLine..., what time processing will be.
I want examine make this utility as external exe, and too as part of main application.
In C utility I have many string manipulation (coding, decoding, lempel ziv algoritm, code page converting..) and file manipulations (read, write from/to ascii file).
OK, first I test it in Xbase , file access will use DC_TxtOpen,TxtLine..., what time processing will be.
I want examine make this utility as external exe, and too as part of main application.
Re: C language and Xbase
Hi,
I made some test for compare speed between C language and Xbase.
I made same program utility in Xbase with using function for read and write to file (fread, fwrite) because it is same as in C utility.
Time processing is for example :
C - 22 sec
Xbase 3 sec
I reading byte to byte from file and write byte to byte, that here is space for optimalization.
So, \exp20\source\dclipc\dcdeftra.c and \exp20\source\dclipc\dckey.c is important for me,
but I mean, function fread , fwrite, respective C functions FGETC, FPUTC is not supported in Xbase
I made some test for compare speed between C language and Xbase.
I made same program utility in Xbase with using function for read and write to file (fread, fwrite) because it is same as in C utility.
Time processing is for example :
C - 22 sec
Xbase 3 sec
I reading byte to byte from file and write byte to byte, that here is space for optimalization.
So, \exp20\source\dclipc\dcdeftra.c and \exp20\source\dclipc\dckey.c is important for me,
but I mean, function fread , fwrite, respective C functions FGETC, FPUTC is not supported in Xbase
Re: C language and Xbase
I haven't written C in a long time.respective C functions FGETC, FPUTC is not supported in Xbase
Refresh my memory what FGETC and FPUTC are for.
The eXpress train is coming - and it has more cars.
Re: C language and Xbase
FGetc read byte/character from file, FPutc write byte/character to file.
Before file must be open by fopen.
It is same than in Xbase Fread, Fwrite, Fopen.
I tested same algorithm in Xbase, but if I read and write in cycle one by one byte it is slower.
Tomorrow I want test read first file to array and then process.
Please, one question, I cannot found it, how many element might have array ?
If file have for example 2MB , 2 000 000 Bytes, can array have 2000000 elements too ?
If I set array to number for example 2500000, error occur,
...LOCAL rbyte[2500000]
Jimmy wrote then I can use to max 2GByte of RAM.
Processed files can have max about 50MB
And second problem, in file are not only ascii codes for letter and numbers, but also other code from ascii table 0 to 254. Than will be problem read file to other type of variable (memo)
Before file must be open by fopen.
It is same than in Xbase Fread, Fwrite, Fopen.
I tested same algorithm in Xbase, but if I read and write in cycle one by one byte it is slower.
Tomorrow I want test read first file to array and then process.
Please, one question, I cannot found it, how many element might have array ?
If file have for example 2MB , 2 000 000 Bytes, can array have 2000000 elements too ?
If I set array to number for example 2500000, error occur,
...LOCAL rbyte[2500000]
Jimmy wrote then I can use to max 2GByte of RAM.
Processed files can have max about 50MB
And second problem, in file are not only ascii codes for letter and numbers, but also other code from ascii table 0 to 254. Than will be problem read file to other type of variable (memo)
Re: C language and Xbase
This is a bad idea.Tomorrow I want test read first file to array and then process.
You would want to read the file into a character string, not an array.
Fread() can read the entire file into a character string.
Then you can access any byte in the character string by one of 2 methods:
1. Use SubStr() - Ex. cByte := Substr( cFileString, 456,1 )
2. Use the index operator - Ex. cByte := cFileString[456]
Arrays consume much more memory than a string.
I have never reached the limit of an array but then I have never created an array of 1 million elements.
I would not ever do this.
The eXpress train is coming - and it has more cars.
Re: C language and Xbase
Why would you want to read binary data into a memo?in file are not only ascii codes for letter and numbers, but also other code from ascii table 0 to 254. Than will be problem read file to other type of variable (memo)
The eXpress train is coming - and it has more cars.
Re: C language and Xbase
hm ... i do not understand what for is it good to read only 1 byte ?Victorio wrote:I tested same algorithm in Xbase, but if I read and write in cycle one by one byte it is slower.
have you ever "test" a HDD / SDD ? they are all slow with "many small" files but fast when (stream) copy huge MP4 Video.
Question : did you test Filesize(), or LEN(String), of both Files before compare ?
RAM Limit for 32bit Application like Xbase++ are 2 GB ... Windows Handle Limit depends on OS()Victorio wrote:Please, one question, I cannot found it, how many element might have array ?
Xbase++ is limited somewhere ( > 100000 ? ) but Alaska have a Patch to increase Xbase++ handles.
2GB = 2000 MB / 2MB -> 1000 ...Victorio wrote:If file have for example 2MB , 2 000 000 Bytes, can array have 2000000 elements too ?
as i say every Array Element need a Windows Handle so have your OS() 2000000 Handles ?
... but why you need so many ? do you want to load all Data from DBF into Array ?
i use Array "as Cache" while every HDD/SDD "read" need time ... "write" even more so why not hold in a Array ?
you have to use AADD() with Xbase++Victorio wrote:If I set array to number for example 2500000, error occur,
...LOCAL rbyte[2500000]
as i say you can read 2 x 500 GB into Memory to compare with Xbase++.Victorio wrote:Jimmy wrote then I can use to max 2GByte of RAM.
Processed files can have max about 50MB
BIN File, like Bitmap, can be used with Type "V" and FoxDBE.Victorio wrote:And second problem, in file are not only ascii codes for letter and numbers, but also other code from ascii table 0 to 254.
Than will be problem read file to other type of variable (memo)
! note : Do NOT use Memoread on BIN Files
greetings by OHR
Jimmy
Jimmy
Re: C language and Xbase
Hi
I did optimalization of code, read full file to variable, and then select byte to byte in this variable with x=textfile.
This help me save some time.
Compare C++ code and Alaska now for process file with size 12MByte is :
C++ code : 6 seconds
Alaska code first example without optimalization byte to byte read from file : 3minutes and 13 seconds
Alaska code optimalized full file read to variable string and so write variable to file once: 18 seconds
It is much better , little slower than C++ but acceptable.
Maybe is possible optimalize code even better, here is source :
* cyklus pre načítavanie znakov z retazca
** velkostsuboru = size of file
i=0
DO WHILE i<velkostsuboru
i++
znak=asc(cSourcestring)
if znak<128
pomznak=znak
for j=0 to pomznak-1
i++
znak=asc(cSourceString)
* znovuskonvertovanie do ascii
cBuffer=chr(znak)
* zápis znaku do výstupného reťazca
cTargetString=cTargetstring+cBuffer
next
else
pomznak=znak-127
* načítanie znaku z reťazca zo zvolenej pozície
i++
znak=asc(cSourceString)
for j=0 to pomznak-1
* znovuskonvertovanie do ascii
cBuffer=chr(znak)
* zápis znaku do výstupného reťazca
cTargetString=cTargetstring+cBuffer
next
endif
ENDDO
I did optimalization of code, read full file to variable, and then select byte to byte in this variable with x=textfile.
This help me save some time.
Compare C++ code and Alaska now for process file with size 12MByte is :
C++ code : 6 seconds
Alaska code first example without optimalization byte to byte read from file : 3minutes and 13 seconds
Alaska code optimalized full file read to variable string and so write variable to file once: 18 seconds

It is much better , little slower than C++ but acceptable.
Maybe is possible optimalize code even better, here is source :
* cyklus pre načítavanie znakov z retazca
** velkostsuboru = size of file
i=0
DO WHILE i<velkostsuboru
i++
znak=asc(cSourcestring)
if znak<128
pomznak=znak
for j=0 to pomznak-1
i++
znak=asc(cSourceString)
* znovuskonvertovanie do ascii
cBuffer=chr(znak)
* zápis znaku do výstupného reťazca
cTargetString=cTargetstring+cBuffer
next
else
pomznak=znak-127
* načítanie znaku z reťazca zo zvolenej pozície
i++
znak=asc(cSourceString)
for j=0 to pomznak-1
* znovuskonvertovanie do ascii
cBuffer=chr(znak)
* zápis znaku do výstupného reťazca
cTargetString=cTargetstring+cBuffer
next
endif
ENDDO