Ehhhhh. Have to butt in. Too many errors.
coder777 wrote: |
---|
C is faster then C++ due to the lack of automatisms like destructor call. |
Destructors that do nothing cost nothing. Destructors that do something cannot be skipped, even in C, or you have resource leaks. Cleanup is important.
The only difference between C and C++ with regard to cleanup is that in C++ the code is called automatically whereas in C you have to do it manually. Either way... cleanup code is still being executed, so neither language is "faster" in this area:
1 2 3 4 5 6 7
|
// C++ code:
std::ifstream foo("myfile"); // ctor opens the file
// dtor closes the file
// C code:
FILE* foo = fopen("myfile","r"); // fopen opens the file
fclose(foo); // fclose closes the file
|
languages like C#, Jave, etc. replaced the destructor call with garbage collection which theoretically reduces that time. |
C# and Java still have destructors. GC does not replace them. GC just goes through allocated memory and removes blocks that are no longer being used.
C and C++ free memory as soon as the object is destroyed. GC languages free it in "clumps" when the GC kicks in. So they're both doing the same work, just at different times.
TheGentlmen wrote: |
---|
all programing languages are turned to 1s and 0s so why would C++ be faster than
[IMPUT LANGUAGE NAME]
? |
The typical answer to this is that C++ is compiled directly into native instructions that the computer can execute directly. IE: actual machine code.
Whereas language like Java and C# are [often, but not always] compiled into "bytecode" which must be interpretted at runtime. IE: their code is not being run directly, but another program is running its own code that looks at and executes your program. Hence why you need Java installed on your computer to run Java programs, but do not need C++ installed on your computer to run a C++ program.
But this is not always the case. Java and C# can both be very fast. And C++ can also be slow. It depends on a lot of things, as Little Bobby Tables said.