C language and Xbase

Xbase++ 2.0 Build 554 or later
Message
Author
Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

C language and Xbase

#1 Post by Victorio »

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

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: C language and Xbase

#2 Post by rdonnay »

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.
The eXpress train is coming - and it has more cars.

Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: C language and Xbase

#3 Post by Victorio »

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.

Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: C language and Xbase

#4 Post by Victorio »

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

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: C language and Xbase

#5 Post by rdonnay »

respective C functions FGETC, FPUTC is not supported in Xbase
I haven't written C in a long time.
Refresh my memory what FGETC and FPUTC are for.
The eXpress train is coming - and it has more cars.

Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: C language and Xbase

#6 Post by Victorio »

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)

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: C language and Xbase

#7 Post by rdonnay »

Tomorrow I want test read first file to array and then process.
This is a bad idea.
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.

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: C language and Xbase

#8 Post by rdonnay »

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)
Why would you want to read binary data into a memo?
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: C language and Xbase

#9 Post by Auge_Ohr »

Victorio wrote:I tested same algorithm in Xbase, but if I read and write in cycle one by one byte it is slower.
hm ... i do not understand what for is it good to read only 1 byte ?
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 ?
Victorio wrote:Please, one question, I cannot found it, how many element might have array ?
RAM Limit for 32bit Application like Xbase++ are 2 GB ... Windows Handle Limit depends on OS()
Xbase++ is limited somewhere ( > 100000 ? ) but Alaska have a Patch to increase Xbase++ handles.
Victorio wrote:If file have for example 2MB , 2 000 000 Bytes, can array have 2000000 elements too ?
2GB = 2000 MB / 2MB -> 1000 ...
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 ?
Victorio wrote:If I set array to number for example 2500000, error occur,
...LOCAL rbyte[2500000]
you have to use AADD() with Xbase++
Victorio wrote:Jimmy wrote then I can use to max 2GByte of RAM.
Processed files can have max about 50MB
as i say you can read 2 x 500 GB into Memory to compare with Xbase++.
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)
BIN File, like Bitmap, can be used with Type "V" and FoxDBE.
! note : Do NOT use Memoread on BIN Files
greetings by OHR
Jimmy

Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: C language and Xbase

#10 Post by Victorio »

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 :violin:

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

Post Reply