const unsigned int MESSAGE_SIZE_PLUS_END_FIELD = MESSAGE_SIZE_FIELD + MESSAGE_END_FIELD;
-const unsigned int MAX_DIVISION_BY_WORD_REMAINDER = sizeof(unsigned int) - 1u; // For word alignment on ARM
+const unsigned int MAX_DIVISION_BY_WORD_REMAINDER = sizeof(Dali::Internal::MessageBuffer::WordType) - 1u; // For word alignment on ARM
+const unsigned int WORD_SIZE = sizeof(Dali::Internal::MessageBuffer::WordType);
} // unnamed namespace
{
MessageBuffer::MessageBuffer( std::size_t initialCapacity )
-: mInitialCapacity( initialCapacity / sizeof(unsigned int) ),
+: mInitialCapacity( initialCapacity / WORD_SIZE ),
mData( NULL ),
mNextSlot( NULL ),
mCapacity( 0 ),
{
DALI_ASSERT_DEBUG( 0 != size );
- std::size_t requestedSize = (size + MAX_DIVISION_BY_WORD_REMAINDER) / sizeof(unsigned int);
+ // Number of aligned words required to handle a message of size in bytes
+ std::size_t requestedSize = (size + MAX_DIVISION_BY_WORD_REMAINDER) / WORD_SIZE;
std::size_t requiredSize = requestedSize + MESSAGE_SIZE_PLUS_END_FIELD;
// Keep doubling the additional capacity until we have enough
}
// Now reserve the slot
- unsigned int* slot = mNextSlot;
+ WordType* slot = mNextSlot;
*slot++ = requestedSize; // Object size marker is stored in first word
// End marker
*mNextSlot = 0;
- return slot;
+ // @todo Remove cast & change all messages to use WordType instead
+ return reinterpret_cast<unsigned int*>(slot);
}
std::size_t MessageBuffer::GetCapacity() const
{
- return mCapacity * sizeof(unsigned int);
+ return mCapacity * WORD_SIZE;
}
MessageBuffer::Iterator MessageBuffer::Begin() const
{
// Often this avoids the need to copy memory
- unsigned int* oldData = mData;
- mData = reinterpret_cast<unsigned int*>( realloc( mData, newCapacity * sizeof(unsigned int) ) );
+ WordType* oldData = mData;
+ mData = reinterpret_cast<WordType*>( realloc( mData, newCapacity * WORD_SIZE ) );
// if realloc fails the old data is still valid
if( !mData )
}
else
{
- mData = reinterpret_cast<unsigned int*>( malloc( newCapacity * sizeof(unsigned int) ) );
+ mData = reinterpret_cast<WordType*>( malloc( newCapacity * WORD_SIZE ) );
}
DALI_ASSERT_ALWAYS( NULL != mData );
mNextSlot = mData + mSize;
}
-MessageBuffer::Iterator::Iterator(unsigned int* current)
+MessageBuffer::Iterator::Iterator(WordType* current)
: mCurrent(current),
mMessageSize(0)
{
class MessageBuffer
{
public:
+ typedef std::ptrdiff_t WordType;
/**
* Create a new MessageBuffer
/**
* Reserve space for another message in the buffer.
* @pre size is greater than zero.
- * @param[in] The message size with respect to the size of type "char".
- * @return A pointer to the address allocated for the message.
+ * @param[in] size The message size with respect to the size of type "char".
+ * @return A pointer to the address allocated for the message, aligned to a word boundary
*/
unsigned int* ReserveMessageSlot( std::size_t size );
public:
// Constructor
- Iterator(unsigned int* current);
+ Iterator(WordType* current);
// Inlined for performance
bool IsValid()
}
// Inlined for performance
- unsigned int* Get()
+ WordType* Get()
{
return ( 0 != mMessageSize ) ? mCurrent : NULL;
}
private:
- unsigned int* mCurrent;
- unsigned int mMessageSize;
+ WordType* mCurrent;
+ std::size_t mMessageSize;
};
/**
std::size_t mInitialCapacity; ///< The capacity to allocate during first call to ReserveMessageSlot
- unsigned int* mData; ///< The data allocated for the message buffer
- unsigned int* mNextSlot; ///< The next free location in the buffer
+ WordType* mData; ///< The data allocated for the message buffer
+ WordType* mNextSlot; ///< The next free location in the buffer
- std::size_t mCapacity; ///< The memory allocated with respect to sizeof(unsigned int)
- std::size_t mSize; ///< The memory reserved for messages with respect to sizeof(unsigned int)
+ std::size_t mCapacity; ///< The memory allocated with respect to sizeof(WordType)
+ std::size_t mSize; ///< The memory reserved for messages with respect to sizeof(WordType)
};
} // namespace Internal