(Appologies for the pun in the subject; I couldn't help myself.. :) )
On Tue, Dec 20, 2005 at 03:52:28PM -0800, Alan M. Evans wrote:
> > void g_string_init(GString *str);
> > void g_string_fini(GString *str);
> >
> > Which would do most of the work of g_string_new() and g_string_free()
> > respectively, apart from the initial struct allocation / final struct
> > free().
> Mine are called g_string_init() and g_string_done().
<snip>
> By using g_string_init() instead of g_string_new() and pointers, I save
> myself four malloc() calls -- a big deal when I have thousands of these
> structs running about. And the bonus is that I can still use all the
> spiffy GString support functions.
>
> I've never dared submit my additions for fear of Owen calling my ideas
> ridiculous. (That's a joke. Owen, please don't ridicule me...)
Well... perhaps now is the time to ask the list for opinions.. I for one
would quite like to see something like this... Baring no objections to
the idea, perhaps I'll make such a change the subject of my next patch
submission.
Arguments for:
* Improvements in malloc() or other allocation space overheads
* Improvements in nested pointer dereferencing
* Ability to build a GArray* containing multiple GString objects
Observations:
* Any function currently taking a GString* can't free or otherwise
modify the GString* object itself, only the data contained with it.
Such functions would not be affected by these 'naked' GStrings.
* There are no g_string_ functions which take a GString** and attempt
to modify it.
Arguments against:
* It does complicate the API slightly.
* Any code using a GString* cannot automatically know whether it was
head-allocated, or just points at a variable somewhere. Whether any
code would actually want to know, or care about such a condition, I
am not currently sure.
[PS: I'm not overly attached to _fini(), _done() seems just as nice.]
--
Paul "LeoNerd" Evans
leonerd leonerd org uk
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
Attachment:
signature.asc
Description: Digital signature