diff --git a/.gitignore b/.gitignore index 0d6d5f8..2266edc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ thirdparty/* *.ilk *.spv *.lib +/bin/basic.exp diff --git a/include/containers/basalt_darray.h b/include/containers/basalt_darray.h index 917c352..ce0aee2 100644 --- a/include/containers/basalt_darray.h +++ b/include/containers/basalt_darray.h @@ -64,11 +64,12 @@ namespace basalt inline darray::darray(const darray& src) { this->m_pdata = mem::allocT(src.m_nelements, src.m_tag); - BASSERT_ERROR(this->m_pdata != nullptr, return, "Assertion %s failed at %s:%d\n\tMemory allocation failed for allocation size %u\n\t%s | %s | %u"); + BASSERT_ERROR(this->m_pdata != nullptr, return; , "Assertion %s failed at %s:%d\n\tMemory allocation failed for allocation size %u\n\t%s | %s | %u"); this->m_tag = src.m_tag; this->m_ncapacity = src.m_nelements; this->m_nelements = src.m_nelements; memcpy(this->m_pdata, src.m_pdata, sizeof(T) * this->m_nelements); + BTRACE("darray<%s> %p was copied to %p (%p)\n", typeid(T).name(), &src, this, this->m_pdata); } template inline basalt::darray& darray::operator=(const darray& src) @@ -77,11 +78,12 @@ namespace basalt return *this; this->~darray(); this->m_pdata = mem::allocT(src.m_nelements, src.m_tag); - BASSERT_ERROR(this->m_pdata != nullptr, return, "Assertion %s failed at %s:%d\n\tMemory allocation failed for allocation size %u\n\t%s | %s | %u"); + BASSERT_ERROR(this->m_pdata != nullptr, return; , "Assertion %s failed at %s:%d\n\tMemory allocation failed for allocation size %u\n\t%s | %s | %u"); this->m_tag = src.m_tag; this->m_ncapacity = src.m_nelements; this->m_nelements = src.m_nelements; memcpy(this->m_pdata, src.m_pdata, sizeof(T)*this->m_nelements); + BTRACE("darray<%s> %p was copied to %p (%p)\n", typeid(T).name(), &src, this, this->m_pdata); } template @@ -95,6 +97,7 @@ namespace basalt src.m_ncapacity = 0; src.m_nelements = 0; src.m_tag = 0; + BTRACE("darray<%s> %p was moved to %p\n", typeid(T).name(), &src, this); } template @@ -111,6 +114,7 @@ namespace basalt src.m_ncapacity = 0; src.m_nelements = 0; src.m_tag = 0; + BTRACE("darray<%s> %p was moved to %p\n", typeid(T).name(), &src, this); return *this; } @@ -134,6 +138,8 @@ namespace basalt new (this->m_pdata + i) T(*(vals.begin() + i)); else BASSERT_FATAL(false, "Assertion %s failed at %s:%d\n\tFailed to copy objects from initializer_list<%s> into darray<%s>\n\t\t%s was not copyable\n", typeid(T).name(), typeid(T).name(), typeid(T).name()); + + BTRACE("darray<%s> %p created: initalizer ctor %p\n", typeid(T).name(), this, this->m_pdata); } template @@ -143,6 +149,7 @@ namespace basalt this->m_ncapacity = 0; this->m_nelements = 0; this->m_tag = tag; + BTRACE("darray<%s> %p created: null ctor %p\n", typeid(T).name(), this, this->m_pdata); } template @@ -154,26 +161,31 @@ namespace basalt this->m_ncapacity = n_capacity; this->m_nelements = 0; this->m_tag = tag; + BTRACE("darray<%s> %p created: capacity ctor %p\n", typeid(T).name(), this, this->m_pdata); } template inline darray::darray(size_t n_elements, const T& fill_value, MEMORY_TAG tag) { - this->m_pdata = mem::allocT(n_capacity, tag); + this->m_pdata = mem::allocT(n_elements, tag); if (this->m_pdata == nullptr) return; - this->m_ncapacity = n_capacity; + this->m_ncapacity = n_elements; this->m_nelements = n_elements; for (size_t i = 0; i < n_elements; ++i) this->m_pdata[i] = fill_value; this->m_tag = tag; + BTRACE("darray<%s> %p created: fill ctor %p\n", typeid(T).name(), this, this->m_pdata); } template inline darray::~darray() { if (this->m_pdata != nullptr) - mem::dealloc(this->m_pdata, this->m_nelements * sizeof(T), this->m_tag); + { + mem::dealloc(this->m_pdata, this->m_ncapacity * sizeof(T), this->m_tag); + BTRACE("darray<%s> %p destroyed %p\n", typeid(T).name(), this, this->m_pdata); + } } template inline void darray::swap(darray& other) @@ -190,9 +202,10 @@ namespace basalt other.m_tag = this->m_tag; this->m_tag = tmp2; - T* tmp = other.m_pdata; + T* tmp3 = other.m_pdata; other.m_pdata = this->m_pdata; - this->m_pdata = tmp; + this->m_pdata = tmp3; + BTRACE("darray<%s> %p (%p) swapped with darray<%s> %p (%p)\n", typeid(T).name(), this, this->m_pdata, typeid(T).name(), &other, this->m_pdata); } template inline void darray::changetag(MEMORY_TAG new_tag) @@ -239,7 +252,7 @@ namespace basalt // Call destructor for objects outside of the new size if (!std::is_trivially_destructible_v) if (new_size < m_nelements) - for (size_t i = new_size; i < this->m_nelements) + for (size_t i = new_size; i < this->m_nelements; ++i) this->m_pdata[i].~T(); this->m_nelements = new_size; @@ -270,14 +283,15 @@ namespace basalt else { BERROR("Can not resize object dynarray<%s>\n\tIt is not trivially copyable, copy assignable, copy constructible, move assignable or move constructable\n", typeid(T).name()); - mem::dealloc(tmp, this->m_ncapacity*sizeof(T), this->m_tag); + mem::dealloc(tmp, new_capacity*sizeof(T), this->m_tag); return; } if (!std::is_trivially_destructible_v) for (size_t i = 0; i < this->m_nelements; ++i) this->m_pdata[i].~T(); - mem::dealloc(this->m_pdata, this->m_nelements*sizeof(T), this->m_tag); + mem::dealloc(this->m_pdata, this->m_ncapacity*sizeof(T), this->m_tag); + BTRACE("darray<%s> %p Resized from %llu (%p) to %llu (%p)\n", typeid(T).name(), this, this->m_ncapacity, this->m_pdata, new_capacity, tmp); this->m_ncapacity = new_capacity; this->m_pdata = tmp; } @@ -304,14 +318,15 @@ namespace basalt else { BERROR("Can not resize object dynarray<%s>\n\tIt is not trivially copyable, copy assignable, copy constructible, move assignable or move constructable\n", typeid(T).name()); - mem::dealloc(tmp); + mem::dealloc(tmp, this->m_nelements*sizeof(T), this->m_tag); return; } if (!std::is_trivially_destructible_v) for (size_t i = 0; i < this->m_nelements; ++i) this->m_pdata[i].~T(); - mem::dealloc(this->m_pdata, this->m_nelements * sizeof(T), this->m_tag); + mem::dealloc(this->m_pdata, this->m_ncapacity * sizeof(T), this->m_tag); + BTRACE("darray<%s> %p (%p) Shrink fit to %llu (%p)\n", typeid(T).name(), this, this->m_pdata, this->m_nelements, tmp); this->m_ncapacity = this->m_nelements; this->m_pdata = tmp; } @@ -398,7 +413,7 @@ namespace basalt BASSERT_FATAL(this->m_nelements > 0, "Assertion %s failed at %s:%d\n\tAttempted to pop an empty darray<%s>\n", typeid(T).name()); if (idx > this->m_nelements) idx = 0; - return *this->m_pdata[idx]; + return this->m_pdata[idx]; } template