/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
VectorBase::VectorBase()
- : mData( NULL )
+ : mData( nullptr )
{
}
{
// adjust pointer to real beginning
SizeType* metadata = reinterpret_cast< SizeType* >( mData );
- // TODO would be nice to memset to a bitpattern to catch illegal use of container after release
- // but that would require knowledge of the itemsize
- free( metadata - 2u );
- mData = 0u;
+
+ delete [] ( metadata - 2u );
+ mData = nullptr;
}
}
if( capacity > oldCapacity )
{
const SizeType wholeAllocation = sizeof(SizeType) * 2u + capacity * elementSize;
- void* wholeData = (void*)malloc( wholeAllocation );
+ void* wholeData = reinterpret_cast< void* >( new uint8_t[ wholeAllocation ] );
+ DALI_ASSERT_ALWAYS( wholeData && "VectorBase::Reserve - Memory allocation failed" );
+
#if defined( DEBUG_ENABLED )
// in debug build this will help identify a vector of uninitialized data
memset( wholeData, 0xaa, wholeAllocation );
// erase can be called on an unallocated vector
if( mData )
{
- char* startAddress = address + elementSize;
- const char* endAddress = reinterpret_cast< char* >( mData ) + Count() * elementSize;
+ uint8_t* startAddress = reinterpret_cast< uint8_t* >( address ) + elementSize;
+ const uint8_t* endAddress = reinterpret_cast< uint8_t* >( mData ) + Count() * elementSize;
SizeType numberOfBytes = endAddress - startAddress;
// addresses overlap so use memmove
memmove( address, startAddress, numberOfBytes );
char* VectorBase::Erase( char* first, char* last, SizeType elementSize )
{
- char* next = NULL;
+ char* next = nullptr;
if( mData )
{
- char* startAddress = last;
- const char* endAddress = reinterpret_cast< char* >( mData ) + Count() * elementSize;
+ uint8_t* startAddress = reinterpret_cast< uint8_t* >( last );
+ const uint8_t* endAddress = reinterpret_cast< uint8_t* >( mData ) + Count() * elementSize;
SizeType numberOfBytes = endAddress - startAddress;
// addresses overlap so use memmove
memmove( first, startAddress, numberOfBytes );