SBASIC & C++

Anything QL Software or Programming Related.
User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: SBASIC & C++

Post by XorA »

C++, which is a faster implementation of 'C'
Erm, no its not, due to its flexibility unless your careful the same code in C++ can actually run slower than C.


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Hi,
Very useful remark.
Do you have any order of magnitude for the difference please?
Steve.


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: SBASIC & C++

Post by XorA »

stevepoole wrote:Hi,
Very useful remark.
Do you have any order of magnitude for the difference please?
Steve.
It depends on the code and what compile options you use. But generally C++ has runtime type checking which adds over head in a lot of places C does not. How much overhead will also depend on which C/C++ compilers you are using.

Basically if you have lots of tight loops and inside the loops you hit a situation where C++ does something more long winded than C then the slowdown will hit your program a lot. If you hit in places only run once you will barely notice it.

But you cannot make bold statements that C or C++ is faster because they are not true.


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: SBASIC & C++

Post by tofro »

Gents,

If you take the very same source code and run it through both a C++ and a C-compiler, the results should basically be 100% identical.
C++ is a superset of C adding object-oriented features - If you don't use them, you shouldn't (or at least only marginally) be hit by them. An intelligent compiler should see you don't use any of the C++ features and not link in the support for it.
What C++ definitely isn't: More performant than C - It's just different.

Regards,
Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Hi,
Thanks for the comparisons of c and c++ guys.

We have transposed an early (short) version of the shrink TSP to C++,and debugged it using system pauses and breakpoints to examine variables. But the results on test values are not yet quite right.

The main difficulty was transposing NEXT and EXIT out off nested inner loops!

To debug further, we need graphics output of LINE and POINT, but the DEVC++ compiler only outputs text. C++ doesn't even seem to have the equivalent of AT x,y or CURSOR x,y.

What we need is a simple cut-down graphics add-on to draw lines, but as far as we know these do not exist. That means buying Borland's Turbo C+ compiler at 5,000 euros... unaffordable for just lines!

Does anyone have any suggestions?
Regards,
Steve.


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: SBASIC & C++

Post by tofro »

You are correct - DevC++ doesn't have graphics functions - like any C you might find.

You can, however, have a look at WinAPI (brrrr.....) or SDL (very much preferred) libraries in order to get at simple to use graphics API for C++.

Regards,
Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Thanks Tofro,
I have downloaded the SDL files, but have not installed them yet.
The site mentions a huge public key. I have no experience of such things.
Did you need this to unzip the files or install them?
Is the installation process straightforward? (There are so many installation instructions for different systems, that this is unclear...)
Regards,
Steve.


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Hi,
We now have C++ graphics access using the QUINCY interface.
The TSP is now almost finished.
But the final problem would appear to stem from a feature of Superbasic : For loop multiple indexes with NEXT and EXIT. I have tried various nested structures, but it is very difficult, even using GOTOs to emulate next and exit, to get the loops to 'fall through' to the required sections.
E.g: FOR f=1 to ctr, z+1 to z+pair
if aa(f): NEXT f: EXIT f
Does anyone know how to code this construct in Cee or C++?
This gem is preventing the TSP from reaching its inner nodes.
We are so close to completion...
Regards,
Steve.


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: SBASIC & C++

Post by tofro »

stevepoole wrote: E.g: FOR f=1 to ctr, z+1 to z+pair
if aa(f): NEXT f: EXIT f
Does anyone know how to code this construct in Cee or C++?
Did you try something like that:

Code: Select all

int i;
for (i = 1; i <= z + pair; i++) {
   if (aa[f])
      continue;

   if (i == ctr);
      i = z + 1;
}
 
Should pretty much do the same thing.

NEXT is functionally equivalent to continue; in C
The non-contiguous ranges in FOR loops can be simulated by assigning a value to the loop variable from inside the loop.

Regards,
Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Many thanks,
The travelling salesman program in C++ now terminates correctly using test results.
But system memory limits array sizes to 256, meaning only some 50 nodes can be calculated. (8000 in superbasic...) So for the moment timings are so instantaneous as to be meaningless...
Does anyone know any way of pumping up memory capacity with C++ on Windows?

This was the first short and rapid version of the TSP. The next version is a longer version which is 100% accurate, whereas the short version achieves only 97%, with an occasional crossover bug. We will be adapting the S*B for CPORT and c68 to test those systems, now that we have aquired some competence in c++.

Progress is now very rapid, and we should soon have comparisons with other TSP heuristics...

Steve.


Post Reply