More evidence that memory safety is the future for programming languages
Dukc
ajieskola at gmail.com
Mon Mar 30 12:58:33 UTC 2020
On Saturday, 28 March 2020 at 20:24:02 UTC, Walter Bright wrote:
> Fitting in with the push for @safe as the default, and the
> @live Ownership/Borrowing system for D.
>
> We can either get on the bus or get run over by the bus.
I have recently added a lot of unittests to my code. That
confirmed me that as we all know, it is a mandatory to do if I
even a remotely bug-free program is desired :). And that's in a
program that already had no global state and used ranges, `final
switch`es and `assert`s fairly much.
So I am thinking, perhaps a dead-easy and well known way to test
correct `malloc`-`free` pairing in unit tests would work just as
well, but be easier to implement and use? It'd be something like
this to use:
```
unittest
{ auto tracer = MallocTracer();
if (true)
{ auto raiiObject = allocAnObject();
raiiObject.doSomething();
assert(tracer.numMallocs == tracer.numFrees - 1);
}
assert(tracer.numMallocs == tracer.numFrees);
}
```
More information about the Digitalmars-d
mailing list