3 ms·
> In Java, say, you have a giant static array. You allocate chunks of that. You can then return to the caller a block of memory without you ever having to call
by tialaramex 5y ago
> In Java, say, you have a giant static array. You allocate chunks of that. You can then return to the caller a block of memory without you ever having to call the OS's allocator.
Where did this "giant static array" come from? Seems like somebody allocated that to you and I think you already know where they got it. Keep going down the rabbit hole.
Somebody is at the bottom of the rabbit hole, and they are not using Java.
- AnimalMuppet 5y agoStatic array. If you wish, it was allocated for you by the JVM, when it started your program. My point is that it wasn't allocated from a call to new(), and if someone calls your function, you don't have to call new() to give them a block. This is in fact an allocator, in the same sense that a C++ arena allocator is an allocator, and in the same sense that malloc is an allocator, and in the same sense that the OS's memory manager is an allocator. They're doing the same things - they're managing a block of memory, and returning sub-blocks of it when requested.
- lmm 5y ago> Somebody is at the bottom of the rabbit hole, and they are not using Java. They're not using C or Rust either, they're writing some kind of machine-specific stub, probably in that machine's assembly language. Yes, a tiny minority of programmers do occasionally have to write the bit-banging stuff that connects hardware to a general-purpose programming language. But that's not a problem that having a different kind of general-purpose programming language helps with.
- tialaramex 5y ago> They're not using C or Rust either, they're writing some kind of machine-specific stub, probably in that machine's assembly language. But that's what's so interesting at the bottom of the rabbit hole. Unlike the languages you've mentioned, the ones used at the bottom of the rabbithole, such as C and Rust, actually provide a mechanism to do exactly that sort of bit-banging. let x: u64; unsafe { asm!("mov {}, 5", out(reg) x); } Isn't that nice? All the surrounding code that isn't doing bit-banging still interoperates with this just fine, so you can do your bit-banging to talk to a memory controller and then... return a freshly allocated chunk of RAM to the rest of the high level code which has whizzy generic types and whatever. Because of Rust's safety rules we're obliged to explicitly flag that we know the compiler can't check our work. If this was serious work, we'd want to provide a comment for humans explaining why this is both necessary and safe, but in this toy example the answer is "No reason at all" so that's redundant. In C, partly due to lack of name spacing, the mechanism is compiler-specific (of course today Rust is effectively wedded to LLVM so for now this is a difference without practical distinction). And there's no safety oversight, you're no more or less at risk when trying to make yet another linked list than when bit-banging. But otherwise it's very similar.
- lmm 5y ago> Isn't that nice? All the surrounding code that isn't doing bit-banging still interoperates with this just fine, so you can do your bit-banging to talk to a memory controller and then... return a freshly allocated chunk of RAM to the rest of the high level code which has whizzy generic types and whatever. It's fine, but it's such a tiny fraction of what matters when producing a product that I wouldn't base my language choice on how good the language's support for that kind of thing is. I don't know exactly how e.g. Singularity or MirageOS do their bit-banging - for all I know they might even use a little bit of C or Rust to bridge the gap - but that bit-banging is such a miniscule proportion of what's important to an OS implementation (much less to an actual product built on that OS) that it shouldn't move the needle on language choice. I've never seen anyone put a genuine effort into running general-purpose language x on bare-metal hardware y and have it fail - it's always "we've tried nothing and we're all out of ideas".