On Friday, 12 October 2018 at 17:31:30 UTC, Neia Neutuladh wrote:
Throwaway scripts can allocate a lot of memory and have
nontrivial running times. It's less common for scripts than for
long-running processes, granted, but I've written scripts to go
through gigabytes of data.
Your point being?.. It's not like you need a GC to allocate
gigabytes of storage. With D it's super easy to just allocate a
huge hunk and simply (literally) slice through it.
People demonstrably have trouble doing that. We can do it most
of the time, but everyone occasionally forgets.
The GC isn't a cure for forgetfulness. One can also forget to
close a file or a socket, or I dunno, cancel a financial
transaction.
GC isn't magic. In fact, to use it correctly you need to pay
*more* attention than when managing memory manually. Don't leave
dangling pointers. Nurse uninitialized data. Massage it to not
sweep in hot paths... People seem to forget that and advertise it
as some sort of magic wand that does all you want without you
having to think.
Beyond that, the concept you're failing to mention here is
ownership. You need to use your own mental effort to figure out
what memory is owned by what part of the code. The GC lets you
ignore that.
Nope, it doesn't. If you "forget" who owns the data, you may as
well "forget" who writes it and when. Would GC help then as well?
You need to expend pretty much the same effort to track that.
Writing a throwaway script there's nothing stopping you from
using mmap or VirtualAlloc. The "power" of GC is in the
language support for non-trivial types, such as strings and
associative arrays. Plain old arrays don't benefit from it in
the slightest.
A string is a plain old array.
An ASCII string, perhaps. Not a Unicode one. Count
statically-typed compiled languages with native strings, please.
and languages with manual memory management also support
associative arrays.
Of course they do. But again, are those built-in types?