3 ms·
> Rust deliberately eschews static constructors and destructors due to their problems, so I presume it would fall foul of this test of yours as well. I would b
by haberman 6y ago
> Rust deliberately eschews static constructors and destructors due to their problems, so I presume it would fall foul of this test of yours as well.
I would be surprised if embedding a string literal into a Rust program would cause a runtime dynamic memory allocation. There is no reason for that: it can be embedded into the binary as static constant-initialized data.
So I would presume the opposite: I would expect that the comparable Rust program would not fail this Valgrind test, because it would not perform any dynamic memory allocation at all.
I don't know anything about V, but I would similarly wonder why this program requires malloc().
- chrismorgan 6y agoThis is true; I contemplated it but decided not to mention it. I haven’t looked into why this V program would be allocating, but I agree with you that the equivalent Rust program would not allocate for this. I decided instead to focus just on the matter of what happens if you do allocate in such a global—which Rust doesn’t let you do directly, you deliberately have to use a trick like lazy_static which constructs on first use and then deliberately leaks so that it never has to destroy.
- xena 6y agoI admit I was wrong, I will use this information in the future to make my blogposts better.