Re: Some new GString functions - constructors



On Tue, 2005-12-20 at 15:38, Paul LeoNerd Evans wrote:

> This idea would require two new functions:
> 
>   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().
> 
> Thoughts on that one?

Actually, you've hit on something I've implemented and used myself, but
for different reasons.

Mine are called g_string_init() and g_string_done(). In my situation, I
have, for example, a struct:

    struct mydata {
        GString one;
        GString two;
        GString three;
        GString four;
    };

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...)





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]