[DEV] remove deprecated code
This commit is contained in:
parent
577d22a5f6
commit
b8ad01984d
451
etk/Vector.hpp
451
etk/Vector.hpp
@ -8,8 +8,6 @@
|
|||||||
#include <etk/types.hpp>
|
#include <etk/types.hpp>
|
||||||
//#include <etk/debug.hpp>
|
//#include <etk/debug.hpp>
|
||||||
#include <etk/Stream.hpp>
|
#include <etk/Stream.hpp>
|
||||||
// better mode of vector ==> increate the code complexity
|
|
||||||
#define ETK_ENABLE_PLACEMENT_NEW 1
|
|
||||||
|
|
||||||
//#define ETK_VECTOR_DEBUG(...) printf(__VA_ARGS__)
|
//#define ETK_VECTOR_DEBUG(...) printf(__VA_ARGS__)
|
||||||
#define ETK_VECTOR_DEBUG(...) do {} while (false)
|
#define ETK_VECTOR_DEBUG(...) do {} while (false)
|
||||||
@ -275,38 +273,20 @@ namespace etk {
|
|||||||
* @brief Re-copy constructor (copy all needed data)
|
* @brief Re-copy constructor (copy all needed data)
|
||||||
* @param[in] _obj Vector that might be copy
|
* @param[in] _obj Vector that might be copy
|
||||||
*/
|
*/
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
Vector(const etk::Vector<ETK_VECTOR_TYPE>& _obj):
|
||||||
Vector(const etk::Vector<ETK_VECTOR_TYPE>& _obj):
|
m_data(nullptr),
|
||||||
m_data(nullptr),
|
m_size(0),
|
||||||
m_size(_obj.m_size),
|
m_allocated(0) {
|
||||||
m_allocated(_obj.m_allocated) {
|
reserve(_obj.m_size);
|
||||||
// allocate all same data
|
for(size_t iii=0; iii<_obj.m_size; iii++) {
|
||||||
m_data = new ETK_VECTOR_TYPE[m_allocated];
|
#if 0
|
||||||
if (m_data == nullptr) {
|
pushBack(_obj.m_data[iii]);
|
||||||
return;
|
#else
|
||||||
}
|
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE(etk::move(_obj.m_data[iii]));
|
||||||
// Copy all data ...
|
#endif
|
||||||
for(size_t iii=0; iii<m_allocated; iii++) {
|
|
||||||
// copy operator ...
|
|
||||||
m_data[iii] = _obj.m_data[iii];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
m_size = _obj.m_size;
|
||||||
Vector(const etk::Vector<ETK_VECTOR_TYPE>& _obj):
|
}
|
||||||
m_data(nullptr),
|
|
||||||
m_size(0),
|
|
||||||
m_allocated(0) {
|
|
||||||
reserve(_obj.m_size);
|
|
||||||
for(size_t iii=0; iii<_obj.m_size; iii++) {
|
|
||||||
#if 0
|
|
||||||
pushBack(_obj.m_data[iii]);
|
|
||||||
#else
|
|
||||||
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE(etk::move(_obj.m_data[iii]));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
m_size = _obj.m_size;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/**
|
/**
|
||||||
* @brief Move operator of elements
|
* @brief Move operator of elements
|
||||||
* @param[in] _obj Object to move
|
* @param[in] _obj Object to move
|
||||||
@ -324,21 +304,17 @@ namespace etk {
|
|||||||
*/
|
*/
|
||||||
~Vector() {
|
~Vector() {
|
||||||
if (m_data != nullptr) {
|
if (m_data != nullptr) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
for(size_t iii=0; iii<m_size; iii++) {
|
||||||
delete[] m_data;
|
m_data[iii].~ETK_VECTOR_TYPE();
|
||||||
#else
|
#ifdef DEBUG
|
||||||
for(size_t iii=0; iii<m_size; iii++) {
|
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
||||||
m_data[iii].~ETK_VECTOR_TYPE();
|
// Only in debug this is really slow ... and for the real allocation of memory
|
||||||
#ifdef DEBUG
|
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
||||||
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
((char*)m_data)[kkk] = 0xA5;
|
||||||
// Only in debug this is really slow ... and for the real allocation of memory
|
}
|
||||||
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
#endif
|
||||||
((char*)m_data)[kkk] = 0xA5;
|
}
|
||||||
}
|
delete[] (char*)m_data;
|
||||||
#endif
|
|
||||||
}
|
|
||||||
delete[] (char*)m_data;
|
|
||||||
#endif
|
|
||||||
m_data = nullptr;
|
m_data = nullptr;
|
||||||
}
|
}
|
||||||
m_allocated = 0;
|
m_allocated = 0;
|
||||||
@ -375,73 +351,33 @@ namespace etk {
|
|||||||
* @param[in] _obj Vector that might be copy
|
* @param[in] _obj Vector that might be copy
|
||||||
* @return reference on the current re-copy vector
|
* @return reference on the current re-copy vector
|
||||||
*/
|
*/
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
Vector& operator=(const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
|
||||||
Vector& operator=(const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
|
// remove all previous elements
|
||||||
if (this != &_obj) {
|
clear();
|
||||||
if (m_data != nullptr) {
|
// Force a specicfic size
|
||||||
delete[] m_data;
|
reserve(_obj.m_size);
|
||||||
m_data = nullptr;
|
for(size_t iii=0; iii<_obj.m_size; iii++) {
|
||||||
}
|
#if 0
|
||||||
// Set the new value
|
pushBack(_obj.m_data[iii]);
|
||||||
m_allocated = _obj.m_allocated;
|
#else
|
||||||
m_size = _obj.m_size;
|
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE(etk::move(_obj.m_data[iii]));
|
||||||
// allocate all same data
|
#endif
|
||||||
m_data = new ETK_VECTOR_TYPE[m_allocated];
|
|
||||||
if (m_data == nullptr) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
for(size_t iii=0; iii<m_allocated; iii++) {
|
|
||||||
// copy operator ...
|
|
||||||
m_data[iii] = _obj.m_data[iii];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Return the current pointer
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
#else
|
m_size = _obj.m_size;
|
||||||
Vector& operator=(const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
|
// Return the current pointer
|
||||||
// remove all previous elements
|
return *this;
|
||||||
clear();
|
}
|
||||||
// Force a specicfic size
|
|
||||||
reserve(_obj.m_size);
|
|
||||||
for(size_t iii=0; iii<_obj.m_size; iii++) {
|
|
||||||
#if 0
|
|
||||||
pushBack(_obj.m_data[iii]);
|
|
||||||
#else
|
|
||||||
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE(etk::move(_obj.m_data[iii]));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
m_size = _obj.m_size;
|
|
||||||
// Return the current pointer
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add at the Last position of the Vector
|
* @brief Add at the Last position of the Vector
|
||||||
* @param[in] _obj Element to add at the end of vector
|
* @param[in] _obj Element to add at the end of vector
|
||||||
*/
|
*/
|
||||||
Vector& operator+= (const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
|
Vector& operator+= (const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
reserve(m_size + _obj.size());
|
||||||
size_t numberElement = _obj.size();
|
for(size_t iii=0; iii<_obj.size(); iii++) {
|
||||||
size_t idElement = m_size;
|
// copy operator ...
|
||||||
resize(m_size+numberElement);
|
new ((char*)&m_data[m_size+iii]) ETK_VECTOR_TYPE(etk::move(_obj.m_data[iii]));
|
||||||
if (m_size <= idElement) {
|
}
|
||||||
//TK_CRITICAL("allocation error");
|
m_size += _obj.size();
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
for(size_t iii=0; iii<numberElement; iii++) {
|
|
||||||
// copy operator ...
|
|
||||||
m_data[idElement+iii] = etk::move(_obj.m_data[iii]);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
reserve(m_size + _obj.size());
|
|
||||||
for(size_t iii=0; iii<_obj.size(); iii++) {
|
|
||||||
// copy operator ...
|
|
||||||
new ((char*)&m_data[m_size+iii]) ETK_VECTOR_TYPE(etk::move(_obj.m_data[iii]));
|
|
||||||
}
|
|
||||||
m_size += _obj.size();
|
|
||||||
#endif
|
|
||||||
// Return the current pointer
|
// Return the current pointer
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -531,38 +467,18 @@ namespace etk {
|
|||||||
* @param[in] _item Element to add at the end of vector
|
* @param[in] _item Element to add at the end of vector
|
||||||
*/
|
*/
|
||||||
void pushBack(ETK_VECTOR_TYPE&& _item) {
|
void pushBack(ETK_VECTOR_TYPE&& _item) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
reserve(m_size+1);
|
||||||
size_t idElement = m_size;
|
new ((char*)&m_data[m_size]) ETK_VECTOR_TYPE(etk::move(_item));
|
||||||
resize(m_size+1);
|
m_size += 1;
|
||||||
if (idElement < m_size) {
|
|
||||||
m_data[idElement] = etk::move(_item);
|
|
||||||
} else {
|
|
||||||
//TK_ERROR("Resize does not work correctly ... not added item");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
reserve(m_size+1);
|
|
||||||
new ((char*)&m_data[m_size]) ETK_VECTOR_TYPE(etk::move(_item));
|
|
||||||
m_size += 1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Add at the Last position of the Vector
|
* @brief Add at the Last position of the Vector
|
||||||
* @param[in] _item Element to add at the end of vector
|
* @param[in] _item Element to add at the end of vector
|
||||||
*/
|
*/
|
||||||
void pushBack(const ETK_VECTOR_TYPE& _item) {
|
void pushBack(const ETK_VECTOR_TYPE& _item) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
reserve(m_size+1);
|
||||||
size_t idElement = m_size;
|
new ((char*)&m_data[m_size]) ETK_VECTOR_TYPE(etk::move(_item));
|
||||||
resize(m_size+1);
|
m_size += 1;
|
||||||
if (idElement < m_size) {
|
|
||||||
m_data[idElement] = etk::move(_item);
|
|
||||||
} else {
|
|
||||||
//TK_ERROR("Resize does not work correctly ... not added item");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
reserve(m_size+1);
|
|
||||||
new ((char*)&m_data[m_size]) ETK_VECTOR_TYPE(etk::move(_item));
|
|
||||||
m_size += 1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Add at the Last position of the Vector
|
* @brief Add at the Last position of the Vector
|
||||||
@ -573,27 +489,15 @@ namespace etk {
|
|||||||
if (_item == nullptr) {
|
if (_item == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
reserve(m_size+_nbElement);
|
||||||
size_t idElement = m_size;
|
if (m_size > m_allocated) {
|
||||||
resize(m_size+_nbElement);
|
//TK_ERROR("Resize does not work correctly ... not added item");
|
||||||
if (idElement > m_size) {
|
return;
|
||||||
//TK_ERROR("Resize does not work correctly ... not added item");
|
}
|
||||||
return;
|
for (size_t iii=0; iii<_nbElement; iii++) {
|
||||||
}
|
new ((char*)&m_data[m_size+iii]) ETK_VECTOR_TYPE(_item[iii]);
|
||||||
for (size_t iii=0; iii<_nbElement; iii++) {
|
m_size += 1;
|
||||||
m_data[idElement+iii] = _item[iii];
|
}
|
||||||
}
|
|
||||||
#else
|
|
||||||
reserve(m_size+_nbElement);
|
|
||||||
if (m_size > m_allocated) {
|
|
||||||
//TK_ERROR("Resize does not work correctly ... not added item");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (size_t iii=0; iii<_nbElement; iii++) {
|
|
||||||
new ((char*)&m_data[m_size+iii]) ETK_VECTOR_TYPE(_item[iii]);
|
|
||||||
m_size += 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void pushBackN(const ETK_VECTOR_TYPE& _value) {
|
void pushBackN(const ETK_VECTOR_TYPE& _value) {
|
||||||
@ -641,57 +545,31 @@ namespace etk {
|
|||||||
pushBack(_item, _nbElement);
|
pushBack(_item, _nbElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
// move current data (after the position)
|
||||||
size_t idElement = m_size;
|
size_t sizeToMove = (m_size - _pos);
|
||||||
// Request resize of the current buffer
|
// Request resize of the current buffer
|
||||||
resize(m_size+_nbElement);
|
reserve(m_size+_nbElement);
|
||||||
if (idElement >= m_size) {
|
if (sizeToMove > 0) {
|
||||||
//TK_ERROR("Resize does not work correctly ... not added item");
|
for (size_t iii=1; iii<=sizeToMove; iii++) {
|
||||||
return;
|
// placement allocate of the element
|
||||||
|
new ((char*)&m_data[m_size+_nbElement-iii]) ETK_VECTOR_TYPE(etk::move(m_data[m_size-iii]));
|
||||||
|
// Remove previous element ==> simplify code.
|
||||||
|
m_data[m_size-iii].~ETK_VECTOR_TYPE();
|
||||||
|
#ifdef DEBUG
|
||||||
|
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
||||||
|
// Only in debug this is really slow ... and for the real allocation of memory
|
||||||
|
for (size_t kkk=(m_size-iii)*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*((m_size-iii)+1); ++kkk) {
|
||||||
|
((char*)m_data)[kkk] = 0xA5;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// move current data (after the position)
|
|
||||||
size_t sizeToMove = (idElement - _pos);
|
|
||||||
if (sizeToMove > 0) {
|
|
||||||
for (size_t iii=1; iii<=sizeToMove; iii++) {
|
|
||||||
// tODO: better explicite the swap...
|
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
|
||||||
m_data[m_size-iii] = etk::move(m_data[idElement-iii]);
|
|
||||||
#else
|
|
||||||
etk::swap(m_data[m_size-iii], m_data[idElement-iii]);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// affectation of all input element
|
|
||||||
for (size_t iii=0; iii<_nbElement; iii++) {
|
|
||||||
m_data[_pos+iii] = etk::move(_item[iii]);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// move current data (after the position)
|
|
||||||
size_t sizeToMove = (m_size - _pos);
|
|
||||||
// Request resize of the current buffer
|
|
||||||
reserve(m_size+_nbElement);
|
|
||||||
if (sizeToMove > 0) {
|
|
||||||
for (size_t iii=1; iii<=sizeToMove; iii++) {
|
|
||||||
// placement allocate of the element
|
|
||||||
new ((char*)&m_data[m_size+_nbElement-iii]) ETK_VECTOR_TYPE(etk::move(m_data[m_size-iii]));
|
|
||||||
// Remove previous element ==> simplify code.
|
|
||||||
m_data[m_size-iii].~ETK_VECTOR_TYPE();
|
|
||||||
#ifdef DEBUG
|
|
||||||
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
|
||||||
// Only in debug this is really slow ... and for the real allocation of memory
|
|
||||||
for (size_t kkk=(m_size-iii)*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*((m_size-iii)+1); ++kkk) {
|
|
||||||
((char*)m_data)[kkk] = 0xA5;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// affectation of all input element
|
// affectation of all input element
|
||||||
for (size_t iii=0; iii<_nbElement; iii++) {
|
for (size_t iii=0; iii<_nbElement; iii++) {
|
||||||
new ((char*)&m_data[_pos-iii]) ETK_VECTOR_TYPE(etk::move(_item[iii]));
|
new ((char*)&m_data[_pos-iii]) ETK_VECTOR_TYPE(etk::move(_item[iii]));
|
||||||
}
|
}
|
||||||
m_size += _nbElement;
|
m_size += _nbElement;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Insert one element in the Vector at a specific position
|
* @brief Insert one element in the Vector at a specific position
|
||||||
@ -729,11 +607,7 @@ namespace etk {
|
|||||||
size_t sizeToMove = (idElement - (_pos+_nbElement));
|
size_t sizeToMove = (idElement - (_pos+_nbElement));
|
||||||
if ( 0 < sizeToMove) {
|
if ( 0 < sizeToMove) {
|
||||||
for (size_t iii=0; iii<sizeToMove; iii++) {
|
for (size_t iii=0; iii<sizeToMove; iii++) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
etk::swap(m_data[_pos+iii], m_data[_pos+_nbElement+iii]);
|
||||||
m_data[_pos+iii] = etk::move(m_data[_pos+_nbElement+iii]);
|
|
||||||
#else
|
|
||||||
etk::swap(m_data[_pos+iii], m_data[_pos+_nbElement+iii]);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Request resize of the current buffer
|
// Request resize of the current buffer
|
||||||
@ -782,11 +656,7 @@ namespace etk {
|
|||||||
size_t sizeToMove = (tmpSize - (_pos+nbElement));
|
size_t sizeToMove = (tmpSize - (_pos+nbElement));
|
||||||
if ( 0 < sizeToMove) {
|
if ( 0 < sizeToMove) {
|
||||||
for (size_t iii=0; iii<sizeToMove; iii++) {
|
for (size_t iii=0; iii<sizeToMove; iii++) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
etk::swap(m_data[_pos+iii], m_data[_pos+nbElement+iii]);
|
||||||
m_data[_pos+iii] = etk::move(m_data[_pos+nbElement+iii]);
|
|
||||||
#else
|
|
||||||
etk::swap(m_data[_pos+iii], m_data[_pos+nbElement+iii]);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Request resize of the current buffer
|
// Request resize of the current buffer
|
||||||
@ -856,45 +726,30 @@ namespace etk {
|
|||||||
* @param[in] _newSize New size of the vector
|
* @param[in] _newSize New size of the vector
|
||||||
*/
|
*/
|
||||||
void resize(size_t _newSize, const ETK_VECTOR_TYPE& _basicElement) {
|
void resize(size_t _newSize, const ETK_VECTOR_TYPE& _basicElement) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
// Reallocate memory
|
||||||
size_t idElement = m_size;
|
if (_newSize > m_size) {
|
||||||
resize(_newSize);
|
if (_newSize > m_allocated) {
|
||||||
if (m_size != _newSize) {
|
changeAllocation(_newSize);
|
||||||
//TK_CRITICAL("error to resize vector");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_newSize > idElement) {
|
|
||||||
// initialize data ...
|
|
||||||
for(size_t iii=idElement; iii<_newSize; iii++) {
|
|
||||||
m_data[iii] = _basicElement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Reallocate memory
|
|
||||||
if (_newSize > m_size) {
|
|
||||||
if (_newSize > m_allocated) {
|
|
||||||
changeAllocation(_newSize);
|
|
||||||
}
|
|
||||||
for (size_t iii=m_size; iii<_newSize; ++iii) {
|
|
||||||
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE(_basicElement);
|
|
||||||
}
|
|
||||||
m_size = _newSize;
|
|
||||||
return;
|
|
||||||
} else if (_newSize == m_size) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
for (size_t iii=m_size; iii<_newSize; ++iii) {
|
for (size_t iii=m_size; iii<_newSize; ++iii) {
|
||||||
m_data[iii].~ETK_VECTOR_TYPE();
|
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE(_basicElement);
|
||||||
#ifdef DEBUG
|
|
||||||
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
|
||||||
// Only in debug this is really slow ... and for the real allocation of memory
|
|
||||||
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
|
||||||
((char*)m_data)[kkk] = 0xA5;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
m_size = _newSize;
|
m_size = _newSize;
|
||||||
#endif
|
return;
|
||||||
|
} else if (_newSize == m_size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (size_t iii=m_size; iii<_newSize; ++iii) {
|
||||||
|
m_data[iii].~ETK_VECTOR_TYPE();
|
||||||
|
#ifdef DEBUG
|
||||||
|
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
||||||
|
// Only in debug this is really slow ... and for the real allocation of memory
|
||||||
|
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
||||||
|
((char*)m_data)[kkk] = 0xA5;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
m_size = _newSize;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Change the current size of the vector
|
* @brief Change the current size of the vector
|
||||||
@ -902,43 +757,31 @@ namespace etk {
|
|||||||
*/
|
*/
|
||||||
void resize(size_t _newSize) {
|
void resize(size_t _newSize) {
|
||||||
ETK_VECTOR_DEBUG("Resize %zu => %zu\n", m_size, _newSize);
|
ETK_VECTOR_DEBUG("Resize %zu => %zu\n", m_size, _newSize);
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
// Reallocate memory
|
||||||
// Reallocate memory
|
if (_newSize > m_size) {
|
||||||
if (_newSize > m_allocated) {
|
if (_newSize > m_allocated) {
|
||||||
changeAllocation(_newSize);
|
changeAllocation(_newSize);
|
||||||
} else if (_newSize == m_allocated) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
for
|
for (size_t iii=m_size; iii<_newSize; ++iii) {
|
||||||
m_size = _newSize;
|
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE();
|
||||||
#else
|
}
|
||||||
// Reallocate memory
|
} else if (_newSize == m_size) {
|
||||||
if (_newSize > m_size) {
|
return;
|
||||||
if (_newSize > m_allocated) {
|
}
|
||||||
changeAllocation(_newSize);
|
ETK_VECTOR_DEBUG("Reduce %zu => %zu\n", m_size, _newSize);
|
||||||
|
for (size_t iii=_newSize; iii<m_size; ++iii) {
|
||||||
|
m_data[iii].~ETK_VECTOR_TYPE();
|
||||||
|
#ifdef DEBUG
|
||||||
|
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
||||||
|
// Only in debug this is really slow ... and for the real allocation of memory
|
||||||
|
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
||||||
|
((char*)m_data)[kkk] = 0xA5;
|
||||||
}
|
}
|
||||||
for (size_t iii=m_size; iii<_newSize; ++iii) {
|
#endif
|
||||||
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE();
|
}
|
||||||
}
|
m_size = _newSize;
|
||||||
} else if (_newSize == m_size) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ETK_VECTOR_DEBUG("Reduce %zu => %zu\n", m_size, _newSize);
|
|
||||||
for (size_t iii=_newSize; iii<m_size; ++iii) {
|
|
||||||
m_data[iii].~ETK_VECTOR_TYPE();
|
|
||||||
#ifdef DEBUG
|
|
||||||
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
|
||||||
// Only in debug this is really slow ... and for the real allocation of memory
|
|
||||||
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
|
||||||
((char*)m_data)[kkk] = 0xA5;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
m_size = _newSize;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
#ifdef ETK_ENABLE_PLACEMENT_NEW
|
|
||||||
void resizeDown(size_t _newSize) {
|
void resizeDown(size_t _newSize) {
|
||||||
ETK_VECTOR_DEBUG("Resize %zu => %zu\n", m_size, _newSize);
|
ETK_VECTOR_DEBUG("Resize %zu => %zu\n", m_size, _newSize);
|
||||||
// Reallocate memory
|
// Reallocate memory
|
||||||
@ -961,7 +804,6 @@ namespace etk {
|
|||||||
}
|
}
|
||||||
m_size = _newSize;
|
m_size = _newSize;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Force the container to have a minimum size in memory allocation
|
* @brief Force the container to have a minimum size in memory allocation
|
||||||
@ -1002,11 +844,7 @@ namespace etk {
|
|||||||
// check if something is allocated :
|
// check if something is allocated :
|
||||||
if (m_data == nullptr) {
|
if (m_data == nullptr) {
|
||||||
// no data allocated ==> request an allocation (might be the first)
|
// no data allocated ==> request an allocation (might be the first)
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
m_data = (ETK_VECTOR_TYPE*)(new char[sizeof(ETK_VECTOR_TYPE)*requestSize]);
|
||||||
m_data = new ETK_VECTOR_TYPE[requestSize];
|
|
||||||
#else
|
|
||||||
m_data = (ETK_VECTOR_TYPE*)(new char[sizeof(ETK_VECTOR_TYPE)*requestSize]);
|
|
||||||
#endif
|
|
||||||
if (m_data == nullptr) {
|
if (m_data == nullptr) {
|
||||||
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
|
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
|
||||||
m_allocated = 0;
|
m_allocated = 0;
|
||||||
@ -1021,16 +859,9 @@ namespace etk {
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
// allocate a new pool of data:
|
// allocate a new pool of data:
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
ETK_VECTOR_TYPE* dataTmp = (ETK_VECTOR_TYPE*)(new char[sizeof(ETK_VECTOR_TYPE)*requestSize]);
|
||||||
ETK_VECTOR_TYPE* dataTmp = new ETK_VECTOR_TYPE[requestSize];
|
|
||||||
#else
|
|
||||||
ETK_VECTOR_TYPE* dataTmp = (ETK_VECTOR_TYPE*)(new char[sizeof(ETK_VECTOR_TYPE)*requestSize]);
|
|
||||||
#endif
|
|
||||||
if (dataTmp == nullptr) {
|
if (dataTmp == nullptr) {
|
||||||
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
|
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
|
||||||
#if 0
|
|
||||||
m_allocated = 0;
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -1043,20 +874,16 @@ namespace etk {
|
|||||||
// copy data in the new pool
|
// copy data in the new pool
|
||||||
size_t nbElements = etk::min(requestSize, m_allocated);
|
size_t nbElements = etk::min(requestSize, m_allocated);
|
||||||
for(size_t iii=0; iii<nbElements; iii++) {
|
for(size_t iii=0; iii<nbElements; iii++) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
// Move in the new element
|
||||||
dataTmp[iii] = etk::move(m_data[iii]);
|
new ((char*)&dataTmp[iii]) ETK_VECTOR_TYPE(etk::move(m_data[iii]));
|
||||||
#else
|
// Remove the old one.
|
||||||
// Move in the new element
|
m_data[iii].~ETK_VECTOR_TYPE();
|
||||||
new ((char*)&dataTmp[iii]) ETK_VECTOR_TYPE(etk::move(m_data[iii]));
|
#ifdef DEBUG
|
||||||
// Remove the old one.
|
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
||||||
m_data[iii].~ETK_VECTOR_TYPE();
|
// Only in debug this is really slow ... and for the real allocation of memory
|
||||||
#ifdef DEBUG
|
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
||||||
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
|
((char*)m_data)[kkk] = 0xA5;
|
||||||
// Only in debug this is really slow ... and for the real allocation of memory
|
}
|
||||||
for (size_t kkk=iii*sizeof(ETK_VECTOR_TYPE); kkk<sizeof(ETK_VECTOR_TYPE)*(iii+1); ++kkk) {
|
|
||||||
((char*)m_data)[kkk] = 0xA5;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// switch pointer:
|
// switch pointer:
|
||||||
@ -1064,11 +891,7 @@ namespace etk {
|
|||||||
m_data = dataTmp;
|
m_data = dataTmp;
|
||||||
// remove old pool
|
// remove old pool
|
||||||
if (dataTmp2 != nullptr) {
|
if (dataTmp2 != nullptr) {
|
||||||
#ifndef ETK_ENABLE_PLACEMENT_NEW
|
delete[] (char*)dataTmp2;
|
||||||
delete[] dataTmp2;
|
|
||||||
#else
|
|
||||||
delete[] (char*)dataTmp2;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set the new allocation size
|
// set the new allocation size
|
||||||
|
Loading…
x
Reference in New Issue
Block a user