apr_palloc return value?

2009-04-08 Thread Juha Korhonen
Hi, when I use apr_palloc function to allocate memory, should I check the
return value to make sure that I really got some memory? Is it possible that
return value is NULL? Documentation about the apr_palloc at
http://apr.apache.org/docs/apr/0.9/group__apr__pools.html says:

 Allocate a block of memory from a pool

Parameters:

  p The pool to allocate from

  size The amount of memory to allocate

Returns:

  The allocated memory


The documentation does not say that it could return NULL...

- JK


Re: apr_palloc return value?

2009-04-08 Thread Nick Kew
On Wed, 8 Apr 2009 22:07:55 +0300
Juha Korhonen mahtav...@gmail.com wrote:

 Hi, when I use apr_palloc function to allocate memory, should I check
 the return value to make sure that I really got some memory?

Yes.

Sort-of.

That is to say, yes you should, but it's common practice to omit
the test, on the dubious grounds that if pool allocation fails,
then your error handling is pretty-much going to fail for the
same reason so it's pointless.

With apr exploring entirely different allocators, that excuse
looks ever more suspect.  So, yes, you're right.

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/


Re: apr_palloc return value?

2009-04-08 Thread Dennis J.

On 04/08/2009 10:13 PM, Nick Kew wrote:

On Wed, 8 Apr 2009 22:07:55 +0300
Juha Korhonenmahtav...@gmail.com  wrote:


Hi, when I use apr_palloc function to allocate memory, should I check
the return value to make sure that I really got some memory?


Yes.

Sort-of.

That is to say, yes you should, but it's common practice to omit
the test, on the dubious grounds that if pool allocation fails,
then your error handling is pretty-much going to fail for the
same reason so it's pointless.


Why?

If I try to allocate 1GB of memory and that fails why is error handling 
pretty-much going to fail after that? There still could be 500MB of ram 
free which would probably be more than enough to handle such an error or is 
there anything fundamentally different compared to to a malloc all (other 
than that it uses a pool)?


Regards,
  Dennis