[hxcommon] CR (hxbuffer.cpp)
Alan Li alanli at real.comcheck a bit more detail on the code. i think the bCopyExistingData=false
case is using either malloc or new to do new allocation which doesn't zero
out the memory block. so i believe it is fine to leave out the zeroout step.
alan,
At 02:30 PM 7/3/2003 -0700, Jonathan H.H. Bloedow wrote:
>Alan:
>
>That's a good question. I guess I can't imagine that actually having the
>data there would be a problem. It depends on whether
>bCopyExistingData=FALSE means "I don't care about copying the existing
>data" or if it means "Absolutely do NOT copy the existing data or I'll cry."
>
>I assume the former. Do you think I should zero out the buffer just to be
>safe?
>
>-- Jonathan
>
>
>At 02:37 PM 7/3/2003 -0700, Alan Li wrote:
>>Jonathan, how about the case copyExistingData being false that you don't
>>want to copy or reuse the data in the buffer? is that taken care
>>somewhere or always reusing the data is no problem at all?
>>alan
>>At 09:33 AM 7/3/2003 -0700, Jonathan H.H. Bloedow wrote:
>>>This change is designed to allow the CHXBuffer to keep track of the size
>>>of the allocation(s) that it has made so that if a buffer is resized
>>>down below its actual allocation size, it can be resized back up to the
>>>original allocation size without doing a completely unnecessary reallocation.
>>>
>>>Please let me know if you see any problems with this implementation.
>>>
>>>Thanks.
>>>
>>>-- Jonathan
>>>
>>>
>>>Index: hxbuffer.cpp
>>>===================================================================
>>>RCS file: /cvs/common/container/hxbuffer.cpp,v
>>>retrieving revision 1.8
>>>diff -b -u -5 -r1.8 hxbuffer.cpp
>>>--- hxbuffer.cpp 23 Apr 2003 16:35:19 -0000 1.8
>>>+++ hxbuffer.cpp 3 Jul 2003 16:27:27 -0000
>>>@@ -99,22 +99,22 @@
>>> #endif
>>>
>>> CHXBuffer::CHXBuffer()
>>> : m_lRefCount(0)
>>> , m_bJustPointToExistingData(FALSE)
>>>- //, m_ulAllocLength(0)
>>>+ , m_ulAllocLength(0)
>>> {
>>> m_BigData.m_pData = NULL;
>>> m_BigData.m_ulLength = 0;
>>> m_BigData.m_FreeWithMallocInterfaceIfAvail = TRUE;
>>>
>>> m_ShortData[MaxPnbufShortDataLen] = 0;
>>> }
>>>
>>> CHXBuffer::CHXBuffer(UCHAR* pData, UINT32 ulLength, BOOL bOwnBuffer)
>>> : m_lRefCount(0)
>>>- //, m_ulAllocLength(ulLength)
>>>+ , m_ulAllocLength(0)
>>> {
>>> m_BigData.m_pData = pData;
>>> m_BigData.m_ulLength = ulLength;
>>> m_BigData.m_FreeWithMallocInterfaceIfAvail = FALSE;
>>>
>>>@@ -138,10 +138,11 @@
>>> {
>>> #ifdef PAULM_HXBUFFERSPACE
>>> LessBufferData(m_ulAllocLength);
>>> #endif
>>> Deallocate(m_BigData.m_pData);
>>>+ m_ulAllocLength = 0;
>>> }
>>> }
>>>
>>> bool CHXBuffer::IsShort() const
>>> {
>>>@@ -336,10 +337,11 @@
>>> {
>>> // New size short, old size big
>>> UCHAR temp[MaxPnbufShortDataLen];
>>> memcpy(temp, m_BigData.m_pData, ulLength); /* Flawfinder:
>>> ignore */
>>> Deallocate(m_BigData.m_pData);
>>>+ m_ulAllocLength = 0;
>>> memcpy(m_ShortData, temp, ulLength); /* Flawfinder: ignore */
>>> }
>>> m_ShortData[MaxPnbufShortDataLen] = (UCHAR)ulLength;
>>> }
>>> else
>>>@@ -347,10 +349,11 @@
>>> if (IsShort())
>>> {
>>> // New size big, old size short
>>>
>>> UCHAR* pNewData = Allocate(ulLength);
>>>+ m_ulAllocLength = ulLength;
>>>
>>> // Allocate new data
>>> // Treat alloc error
>>> if (!pNewData)
>>> {
>>>@@ -375,20 +378,27 @@
>>> // Mark data as big
>>> m_ShortData[MaxPnbufShortDataLen] = BigDataTag;
>>> }
>>> else
>>> {
>>>+ if( ulLength <= m_ulAllocLength )
>>>+ {
>>>+ m_BigData.m_ulLength = ulLength;
>>>+ m_BigData.m_FreeWithMallocInterfaceIfAvail = TRUE;
>>>+ return HXR_OK;
>>>+ }
>>> // New size big, old size big
>>> // Reallocate the data
>>> UCHAR* pTemp = copyExistingData
>>> ? Reallocate(m_BigData.m_pData, m_BigData.m_ulLength,
>>> ulLength)
>>> : Allocate(ulLength);
>>> // Treat alloc error
>>> if (!pTemp)
>>> {
>>> return HXR_OUTOFMEMORY;
>>> }
>>>+ m_ulAllocLength = ulLength;
>>> // Deallocate old memory
>>> if (!copyExistingData)
>>> {
>>> Deallocate(m_BigData.m_pData);
>>> }
>>>Index: pub/hxbuffer.h
>>>===================================================================
>>>RCS file: /cvs/common/container/pub/hxbuffer.h,v
>>>retrieving revision 1.5
>>>diff -b -u -5 -r1.5 hxbuffer.h
>>>--- pub/hxbuffer.h 4 Mar 2003 21:01:32 -0000 1.5
>>>+++ pub/hxbuffer.h 3 Jul 2003 16:27:27 -0000
>>>@@ -65,12 +65,11 @@
>>> : public IHXBuffer
>>> {
>>> protected:
>>>
>>> LONG32 m_lRefCount;
>>>-
>>>- //ULONG32 m_ulAllocLength;
>>>+ ULONG32 m_ulAllocLength;
>>> BOOL m_bJustPointToExistingData;
>>>
>>> #if !defined(HELIX_CONFIG_NOSTATICS)
>>> // Interface for optional allocator
>>> static IMalloc* m_zMallocInterface;
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: dev-unsubscribe at common.helixcommunity.org
>>>For additional commands, e-mail: dev-help at common.helixcommunity.org
>>
>>
>>------------------------------------------------------------------------------------------
>>Alan Li, Technical Lead,
>>RealNetworks, Inc. Email: alanli at real.com
>>2601 Elliott Avenue Phone: (206)892-6032
>>Seattle, WA 98121 http://www.realnetworks.com
>>------------------------------------------------------------------------------------------
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe at common.helixcommunity.org
>For additional commands, e-mail: dev-help at common.helixcommunity.org
>
------------------------------------------------------------------------------------------
Alan Li, Technical Lead,
RealNetworks, Inc. Email: alanli at real.com
2601 Elliott Avenue Phone: (206)892-6032
Seattle, WA 98121 http://www.realnetworks.com
------------------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe at common.helixcommunity.org
For additional commands, e-mail: dev-help at common.helixcommunity.org