Right now i'm trying to get my code(simple POD containers) running as stable as humanly possible. My main concern is memory allocation and deallocation(new[] and delete[] operators). Is it possible to get any undesired behavior out of them(like SIGSEGV or exceptions)? Here's a little test example i wrote:
class my_vector{
private:
long* _data;
size_t _size;
size_t _capacity;
public:
my_vector()
{
this->_data = new long[10];
this->_size = 0;
this->_capacity = 10;
};
~my_vector()
{
delete[] this->_data;
};
void add(long value)
{
if (this->_size == this->_capacity)
this->expand();
this->_data[this->_size] = value;
this->_size++;
};
private:
void expand()
{
long* tmp = new long[this->_capacity*2];
memcpy(tmp, this->_data, sizeof(long)*this->_size);
this->_capacity *= 2;
delete[] this->_data;
this->_data = tmp;
};
}