Skip to content

Commit

Permalink
STYLE: Replace ptr = new T; memset(ptr, 0, sizeof(T)) with new T()
Browse files Browse the repository at this point in the history
Simplified code by replacing

    ptr = new T;
    memset(ptr, 0, sizeof(T))

with `ptr = new T()`.
  • Loading branch information
N-Dekker committed Oct 6, 2024
1 parent 321ed55 commit 3d7f501
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
6 changes: 1 addition & 5 deletions Modules/Core/Common/test/itkFixedArrayTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ itkFixedArrayTest2(int, char *[])
// Declare an array of nelements FixedArray
// and add a small margin to play with pointers
// but not map outside the allocated memory
auto * vec = new ArrayType[nelements + 8];

// Fill it up with zeros
memset(vec, 0, (nelements + 8) * sizeof(ArrayType));

auto * vec = new ArrayType[nelements + 8]();

// Display the alignment of the array
std::cout << "Initial alignment: " << (((size_t)vec) & 7) << '\n';
Expand Down
3 changes: 1 addition & 2 deletions Modules/IO/GE/src/itkGE5ImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ GE5ImageIO::ReadHeader(const char * FileNameToRead)
<< "Reason: " << reason);
}

curImage = new GEImageHeader;
memset(curImage, 0, sizeof(GEImageHeader));
curImage = new GEImageHeader();

std::ifstream f;
this->OpenFileForReading(f, FileNameToRead);
Expand Down

0 comments on commit 3d7f501

Please sign in to comment.