Problem: C style malloc and free

Solution: use new and delete
This commit is contained in:
Gudmundur Adalsteinsson 2021-02-18 20:31:55 +00:00
parent 54c7f7969b
commit 4b61c67ef0

View File

@ -46,7 +46,7 @@ template <typename T, size_t S> class fast_vector_t
explicit fast_vector_t (const size_t nitems_)
{
if (nitems_ > S) {
_buf = static_cast<T *> (malloc (nitems_ * sizeof (T)));
_buf = new (std::nothrow) T[nitems_];
// TODO since this function is called by a client, we could return errno == ENOMEM here
alloc_assert (_buf);
} else {
@ -59,7 +59,7 @@ template <typename T, size_t S> class fast_vector_t
~fast_vector_t ()
{
if (_buf != _static_buf)
free (_buf);
delete[] _buf;
}
private: