I don't know that, that is why I ask in this topic.
C/C++ which one efficient, fast and with more possibilities...
I don't know that, that is why I ask in this topic.
C/C++ which one efficient, fast and with more possibilities...
Actually, since Java passes all objects by reference and therefore doesn't make a lot of copies, I believe there are some cases in which Java could be faster than C/C++ (unless the C/C++ code is written very carefully).
I just hate Java's lack of type safety though (i.e. no const keyword...)
In C you have to explicitly "ask" (or allocate) memory, and "free" (or deallocate) memory. If you mess this up your program can have a memory leak, which causes it to keep using more and more ram.
In Java, there is a built in component called the Garbage collector. All allocation and deallocation is handled for you.
As for the libraries, there are no standard libraries like java.sql.*. There are many third party libraries, but its your job to dig through them and figure out which one is best for your needs (in the case of DBMS access, ODB will be your friend with C). Once you've done that, there are no standard conventions about how the library is used or even the coding conventions. So you can end up with function_calls_like_this() for one lib, andOthersLikeThis() for anther, xyzSAN_andSomeLikeThis().... etc... It makes your code awkard to read and write.
Oh come on, speed isn't only from references. Speed is from fast libraries and not some crap garbage collector that sites in the background eating up CPU cycling through all memory you have and see if it's not being used anymore.
C/C++ along with assembly, which it walks hand-in-hand with almost, will always be at the top of the speed chain.
Can you pleas give me an example? but in C we don't have objects !! or not ?since Java passes all objects by reference and therefore doesn't make a lot of copies
Elysia,
No, I don't want emulators => that's too technical ... I just want in the future to make programs processing data and save it to databases ..
We have structs!
Code:typedef struct { int a, b, c; } mystruct; void foo(mystruct* p) { } void foo2(mystruct p) { } int main() { mystruct astruct; foo(&astruct); /* Pass as pointer or reference as some call it */ foo2(astruct); /* Copy the entire struct and pass it */ return 0; }
@Perspective
Thank you, .. do you do that ? you are programming on a very low layer if you operate the memory .. you can program virus with C
I think it's a lot work to do this memory management!
Well, it may be a slight problem, but then again, if you define strict rules for it, then it usually isn't that bad of a problem. It also gives you speed since you can explicitly control when to free the memory.
In C++, you can build classes around memory handling (like Boost's smart pointers) to take away memory handling from your hands.
C and C++ is a very low level language. You can directly manipulate memory and mess around with it if you want (I bet you can't do that in Java).
But this also makes C/C++ very unsafe.
@Elysia
Yes, I was reading today in a book about differences between C and Java and I read about pointers in C using stars but there is no pointer in Java.
The Question is: no pointers in Java : does that mean Java is beter ?
ps: I'm learling now the basics of C ...
Depending on how you "define" Virus, it may be possible to do so, but I think most actual code that distributes itself within the executable file of other files are written in assembler - mostly because they don't do anything really complex, so there's no point in using a higher level language. There are only a few people who ACTUALLY write this type of code - others take the code and tweak it.
Memory management is something that needs to be done by someone somewhere. The original reason for C++ even being invented was that the Simula-67 language that Bjarne Stroustrup used before coming up with C++ has a "garbage collection" method of memory management, which was OK when the system was running small loads - but [in the implementation Bjarne was working with] when the amount of memory usage was high, the time spent in garbage collection was much higher than in the code actually running in the simulation. C and C++ lets the user decide when memory is freed - this increases freedom, but with freedom comes responsibility. As with most things, there's a positive and a negative side to almost everything.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Learn how to program, then talk about the pros and cons of language features (or "misfeatures", as the case may be). If you are new to programming and are currently learning the basics of C, a discussion on pointers with respect to C versus Java is beyond you since you do not know Java and barely know C.The Question is: no pointers in Java : does that mean Java is beter ?
ps: I'm learling now the basics of C ...
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
@matsp
Virus according to me is a program which destroys your files and data or make your computer working slowly ..
Yes now I understand memory management and garbage collection .. in Java we don't have to do that because it is the job of JVM (Java Virtual Machine).
But you can never make virus destorying the system time memory (BIOS)
Source: Mr. Google.
Note that even though a language may call it references there are no such things. In machine language, there are only pointers. So the code that's generated are pointers. Basically variables that holds a memory address to an object.
So yes, both C and Java can do pointers.