[ccan] help with gracefully dealing with alloc failure in a recursive function

Bart Grantham bart at bartgrantham.com
Tue Oct 11 02:52:27 EST 2011


On Mon, Oct 10, 2011 at 3:28 AM, David Gibson
<david at gibson.dropbear.id.au>wrote:

> On Mon, Oct 10, 2011 at 02:26:51AM -0400, Joey Adams wrote:
> >
> > Running out of memory does not mean the application cannot return to a
> > sane state.  Maybe the user was trying to load a 500MB file.  In this
> > case, the error handling code will free a lot of memory.
>
> In theory, yes.  In practice, no-one will bother since running out of
> memory is vanishingly rare on a modern VM system, except in situations
> where you have bigger problems than your XML app dying.
>

Not all systems where ccan would be useful have VM.  Embedded systems, for
example.

Joey, I'm not sure of how you wanted TTXML to "feel" as an API but if you're
shooting for single-pass parsing (presumably for reasons of simplicity or
efficiency?) it might be better to skip the intermediate
parsing/tree-building step and instead support something like an XPath
expression + a function that will operate on the matching node(s).  It could
make your code significantly more complex, especially if you try to support
all of the XPath syntax, but for the cases where single-pass is required
(streaming the object through memory, for example) it might make more sense
for the end-user.  And it would make it easier to predict and constrain the
memory usage of the algorithm.

BG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20111010/f748fbf5/attachment.html>


More information about the ccan mailing list