Skip to content

Commit df221c5

Browse files
committed
add clear(), 2D + 3D array
1 parent d4ca1e4 commit df221c5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/psram_unique_ptr.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,17 @@ class ps_array2d
15111511
return alloc_internal(m_dim1, m_dim2);
15121512
}
15131513

1514+
void clear() {
1515+
if (!is_allocated()) {
1516+
// nothing to do if there is no memory assigned
1517+
return;
1518+
}
1519+
// calculate the total number of elements
1520+
const size_t total_elements = m_dim1 * m_dim2;
1521+
// set the entire memory block to zero
1522+
std::memset(m_data.get(), 0, total_elements * sizeof(T));
1523+
}
1524+
15141525
// Klammer-Operator für den Zugriff auf einzelne Elemente (Bounds-Check inklusive)
15151526
T &operator()(size_t i, size_t j)
15161527
{
@@ -1662,6 +1673,17 @@ class ps_array3d{
16621673
return alloc_internal(m_dim1, m_dim2, m_dim3);
16631674
}
16641675

1676+
void clear(){
1677+
if (!is_allocated()) {
1678+
// Nichts zu tun, wenn kein Speicher zugewiesen ist
1679+
return;
1680+
}
1681+
// Berechne die Gesamtanzahl der Elemente
1682+
const size_t total_elements = m_dim1 * m_dim2 * m_dim3;
1683+
// Setze den gesamten Speicherblock auf null
1684+
std::memset(m_data.get(), 0, total_elements * sizeof(T));
1685+
}
1686+
16651687
// Klammer-Operator für den Zugriff auf einzelne Elemente
16661688
T &operator()(size_t i, size_t j, size_t k)
16671689
{

0 commit comments

Comments
 (0)