List of Phobos functions that allocate memory?
Jakob Ovrum
jakobovrum at gmail.com
Sun Feb 9 04:02:23 PST 2014
On Sunday, 9 February 2014 at 04:38:23 UTC, Marco Leise wrote:
> Yes, it doesn't seem feasible otherwise. Since you can call
> functions recursively you could potentially chain exceptions
> from the same line of code several times.
>
> catch (Exception e)
> {
> staticException.line = __LINE__;
> staticException.file = __FILE__;
> staticException.next = e; // e.next is staticException
> throw staticException;
> }
>
> You'd have to flag staticException as "in use" and spawn a new
> instance every time you need another one of the same type.
> Since there is no way to reset that flag automatically when
> the last user goes out of scope (i.e. ref counting), that's
> not even an option.
>
> Preallocated exceptions only work if you are confident your
> exception wont be recursively thrown and thereby chained to
> itself. Granted, the majority of code, but really too much
> cognitive load when writing exception handling code.
While writes directly to line and file and such can't be
prevented, `next` could be implemented as a property that does
the conditional .dup when assigned to itself (or throw an Error).
More information about the Digitalmars-d
mailing list