4 ms·
> in my experience any halfway decent general-purpose programming language can be used in every domain if you actually try That's going to be an extremely limi
by tialaramex 5y ago
> in my experience any halfway decent general-purpose programming language can be used in every domain if you actually try
That's going to be an extremely limited experience. Most of the world's general-purpose languages have a heavy runtime. The runtime is expected to provide the running program with all manner of conveniences, but one very common item that you've probably imagined is just "universal" is an allocator so that you can... allocate memory. Nope. What programming language do you think the allocator is written in? Languages like C and Rust are designed with such a runtime as only an optional extra, so that you can in fact write the allocator in those languages.
- lmm 5y ago> Most of the world's general-purpose languages have a heavy runtime. "Heavy" by 1970 standards perhaps. When e.g. ML was first created, the newest and fanciest PCs had 512Kb of RAM. Nowadays if you wanted to buy a microcontroller with such a small amount of RAM you'd have to pay extra because you're asking for a lower-volume specialised part. > What programming language do you think the allocator is written in? Any language where someone actually bothered to actually try to write one - writing them in high-level languages has been done plenty of times with plenty of techniques (perhaps most elegantly in T by just carefully writing the allocator code such that it's not doing any allocations in the allocator itself). "Not actually needing to write a custom allocator" is also very easy in every domain if you actually try, IME.
- tialaramex 5y ago"by just carefully writing the allocator code such that it's not doing any allocations in the allocator itself" The tautology you've inadvertently described there isn't actually an allocator. Isn't that fascinating? I can't tell if you were trying to be clever or if you just didn't see what you were doing. What's actually going on is that T is sat on top of an entire operating system (often a Unix) which provides it with an allocator. It then uses garbage collection so that the lay user needn't worry about, like many high level languages.
- AnimalMuppet 5y agoNo, it can be done. 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. But I disagree with lmm's larger point, and I will give my own example of it. Here's an embedded system that controls the wing surfaces on a fighter aircraft. It has to adjust them every 1/40th of a second, or the wings break off (not an exaggeration). So a big part of the development process is proving that you always meet that timing. You do things like count the CPU cycles used by the code that the compiler generates. Then someone says "let's use a garbage-collected language!" Worse, they may even suggest a language that automatically allocates. They might say that you can get garbage collectors and allocators that have guaranteed-worst-case timings. But even then, you have to count the allocations, multiply by the worst-case time of an allocation, and figure in the garbage collection time. And you're faced with a bunch of cynical embedded engineers, asking "Explain to me again how this makes our lives easier?" And you can't, because it doesn't. You can write just about anything in just about any language. But software engineers aren't stupid, and they aren't sheep. The tools typically chosen for an area are usually better for doing actual work in that area.
- 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.