Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Generally it's really difficult to write pointer chasing code in pure C.

Why C programs run fast is because a single line of C does so little, therefore the only way to write C effectively is to make you code not do much. Since you don't have GC you have to think about how to structure your code in a such a way to minimize allocations. When you minimize allocations your program (and data) tends to reside and stay in cache.

All of this leads to programs that do very little and thus are very fast. If you made a C version of minecraft that does all the things the java? version (waste time scanning objects to see if they are in use, looking up vtables, etc) then the C version will run just as slow.

Alternatively if you write C style Java it tends to run about as fast as C.



Very good answer, thanks for that!


how would you write C stye java ?


0P probably means don't create/use a lot of classes, use a lot of static methods, globals, memory maps, arrays, enums, primitives, and try to reuse objects. Other than that totally uninformed answer, I dunno.


When you write a line of java think how would I write this in C.

If you'd write it the same in C then keep going, if not rethink your solution.

eg. Don't use the string class, use an array of char, Don't use objects, etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: