You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Nicolás Lichtmaier <ni...@reloco.com.ar> on 2004/05/18 01:43:12 UTC

Why passing a pool to a printf?

Why not creating and destroying a pool with each printf? Why cluttering 
the interface, requiring other functions to also include a pool? And 
what about this:

for(i=0 ; i<10000 ; i++)
        svn_cmdline_printf(pool, "file %s\n", files[i]);

Won't this take lots of memory?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Why passing a pool to a printf?

Posted by Branko Čibej <br...@xbc.nu>.
Nicolás Lichtmaier wrote:

>
>>> Why not creating and destroying a pool with each printf?
>>>   
>>
>>
>> Creating and destroying a pool is moderately expensive.
>>
>> Also, we don't like creating pools entirely from scratch.  This way, the
>> printf implementation can allocate memory and not worry about cleaning
>> it up if it has to error out.
>>  
>>
>
> Oh, I see...
>
> Would it be overkill to maintain a hashtable with pools, with one pool 
> per thread? =)

Yes, becasue you'd have to control access to the hash table. Really, it 
doesn't make sense to do that.




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Why passing a pool to a printf?

Posted by Nicolás Lichtmaier <ni...@reloco.com.ar>.
>>Why not creating and destroying a pool with each printf?
>>    
>>
>
>Creating and destroying a pool is moderately expensive.
>
>Also, we don't like creating pools entirely from scratch.  This way, the
>printf implementation can allocate memory and not worry about cleaning
>it up if it has to error out.
>  
>

Oh, I see...

Would it be overkill to maintain a hashtable with pools, with one pool 
per thread? =)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Why passing a pool to a printf?

Posted by Greg Hudson <gh...@MIT.EDU>.
On Mon, 2004-05-17 at 21:43, Nicolás Lichtmaier wrote:
> Why not creating and destroying a pool with each printf?

Creating and destroying a pool is moderately expensive.

Also, we don't like creating pools entirely from scratch.  This way, the
printf implementation can allocate memory and not worry about cleaning
it up if it has to error out.

>  Why cluttering the interface, requiring other functions to also
>  include a pool?

Just about all of our public functions require a pool.  Where they
don't, it usually means we screwed up.  Perhaps it clutters the
interfaces, but it makes the implementations easier.

> And  what about this:

> for(i=0 ; i<10000 ; i++)
>         svn_cmdline_printf(pool, "file %s\n", files[i]);

> Won't this take lots of memory?

Yes.  That's why we have this idiom documented in HACKING:

  subpool = svn_pool_create (pool);
  for (blah)
    {
      svn_pool_clear (subpool);
      stuff (..., subpool);
    }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org


Re: Why passing a pool to a printf?

Posted by Branko Čibej <br...@xbc.nu>.
Nicolás Lichtmaier wrote:

> Why not creating and destroying a pool with each printf?

Because it allocates memory for argument interpolation and charser 
conversion.

> Why cluttering the interface, requiring other functions to also 
> include a pool?

Because in most places, a pool is already available. I suppose we could 
make the pool parameter optional and have svn_cmdline_printf create its 
own pool if it's NULL, but that would make this function inconsistent 
with every other function in Subversion that creates a pool.

I don't think there are that many places where a pool is not already handy.

> And what about this:
>
> for(i=0 ; i<10000 ; i++)
>        svn_cmdline_printf(pool, "file %s\n", files[i]);
>
> Won't this take lots of memory?

Oh fi. We have guidelines for that. See HACKING, section "APR pool usage 
conventions".

-- Brane



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org