4 ms·
Like, what? Honest question. I can think of a few things that Java does (bounds checking, for one), but very few things that C does. (also, not entirely sure w
by virgilp 3y ago
Like, what? Honest question. I can think of a few things that Java does (bounds checking, for one), but very few things that C does.
(also, not entirely sure what you meant. There isn't a canonical C compiler, or toolset, and the language itself really doesn't do anything to prevent you from shooting yourself in the foot)
- marginalia_nu 3y agoLike having unsigned integers and pointers. Java makes you do pointer arithmetic with all signed integers that all have the same type as every other integer in the program.
- afandian 3y agoWhat do you mean by pointer arithmetic in Java? Real pointers in FFI? Or array indexes?
- marginalia_nu 3y agoOffsets in files and mapped memory. None of this is done through Java objects or arrays, but rather by reading data directly from memory or disk and manually keeping track the data's type and structure.
- deely3 3y agoAnd how exactly C is better in these situations?
- marginalia_nu 3y agoIt has pointer types and unsigned integer types.
- shrx 3y agoIf you're using pointers in Java you're doing something wrong
- marginalia_nu 3y agoIf you're going to do this sort of low level database-adjacent work in Java, this is basically how you need to do it. It's pretty unpleasant and the language resists you in every way, but luckily in most cases it's only a small core of the program that needs to be written this way. Well, that or JNI/FFI in some C code I guess.
- mike_hearn 3y agoDoes the new Panama memory API help? There are new pointer-like classes for indexing into memory mapped files. Also, Kotlin has unsigned integers. So you could use that for the parts of your code that benefit from it.
- marginalia_nu 3y agoIt helps in the sense that it's no longer necessary to slice up the file into individual 2 GB byte buffers, though I'm not really using MemoryLayout/StructLayout much yet to do structured access. Haven't made sense of how to use that part of the API well yet.