On Sep 17, 2013, at 05:59 PM, Tom Browder <tom.brow...@gmail.com> wrote:

That may be, but I also see more complexity in trying to initialize
those parts that can't be static initialized. Also, using both
methods would require two kinds of array handling, etc.

Hm, I guess I assumed it could all be static-initialized.  What cannot?  It should be the same handling whether the memory/arrays are dynamic or on the stack.  The only change is whether bu_arg_*() or the caller is expected to allocate memory.

As I work on the new interface, I find myself going toward a separate
arg init function for each TCLAP type we implement, each having its
own signature which parrots the TCLAP class. Then the common struct
is actually initialized behind the scenes. That way we also
piggy-back on the TCLAP manual for how to use each type.

Don't follow and probably won't until your example is complete so I'll defer commenting further.

As far as memory handling goes, the user will only have to do one
bu_arg_free for the array that contains the arg pointers (of course
multiple controlled error exits will require a bu_arg_free for
each)--that's pretty easy I think.
 
And that's the problem that would be great to avoid if at all possible.  If not, so be it, but it's more than something "nice to have" given this is at the heart of every command and utility we have.

It's not just a good best-practice in general, but our own code experience has shown that properly handling memory in exception conditions is something we're not good at (nobody is).  Especially given enough time and different eyes on the code..

You might know that a *free() needs to be called before all return statements now, but that new dev that looks at the code in 5 years doesn't.  It's trivial to miss it during code review too, to see some block needs a *free() sometimes years later.  We weeded out hundreds of those cases that Coverity detected last year, but there are more.

Again, if it's needed, so be it and we deal.  But I'd be curious what construct we have that cannot be static initialized and even still if there's some way to structure the API to support stack memory.  This will become even more important as we continue to migrate command-line commands into plugin infrastructure.

Cheers!
Sean

------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to