Re: [PATCH] Reinstate Mempools useage for MemBlob

From: Kinkie <gkinkie_at_gmail.com>
Date: Wed, 6 Apr 2011 13:45:51 +0200

>> I suggest removing MemBlob::calcAllocSize() completely and moving any
>> still relevant comments to mem.cc.
>>
>>
>>> -#if MEMBLOB_USES_MEM_POOLS
>>> -    //no mempools for now
>>> -    // \todo reinstate mempools use
>>>      memFreeString(capacity,mem);
>>
>> memFreeString() does not handle deallocation of nil buffers IIRC. It is
>> very unlikely but still possible that the mem buffer remains nil in the
>> destructor if we hit an exception somewhere along the way to the mem
>> allocation call. Let's handle that case gracefully here or in
>> memFreeString():
>>
>>     if (mem || capacity)
>>        memFreeString(capacity,mem);
>>
>>
>> I think this patch can go in after the above polishing touches.
>
> Good point.
>
> Though if it is pushed inside memFreeString (I think it should) that would
> make it a part of the mem.cc alterations prior to this optimization polish.

I haven't done this yet.
However at this time it seems impossible to get in such a state:
xmalloc is basically c, it shouldn't throw but fail by returning null
and this will be raised during allocation (most likely by asserting).
Requesting allocation of a zero-sized valid String will result in it
being ballooned to a valid-sized string. In other words, I'm worried
that explicitly handling this case will actually decrease the general
robustness against misbehaving callers

-- 
    /kinkie
Received on Wed Apr 06 2011 - 11:45:58 MDT

This archive was generated by hypermail 2.2.0 : Wed Apr 06 2011 - 12:00:15 MDT