-
-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
itkImportImageContainer AllocateElements documentation doesn't seem right #4359
Labels
type:Documentation
Documentation improvement or change
Comments
issakomi
added a commit
to issakomi/ITK
that referenced
this issue
Dec 3, 2023
Comment are variable names better describe the behavior of the ImportImageContainer. Closes InsightSoftwareConsortium#4359
issakomi
added a commit
to issakomi/ITK
that referenced
this issue
Dec 3, 2023
Comments are variable name describe the behavior of the ImportImageContainer better. Closes InsightSoftwareConsortium#4359
issakomi
added a commit
to issakomi/ITK
that referenced
this issue
Dec 3, 2023
Comments are variable name describe the behavior of the ImportImageContainer better. Closes InsightSoftwareConsortium#4359
issakomi
added a commit
to issakomi/ITK
that referenced
this issue
Dec 4, 2023
Comments and the variable name better describe the behavior of the ImportImageContainer. The variable name in VectorImage has also been updated. Closes InsightSoftwareConsortium#4359
Thanks @issakomi FYI, value-initialization is also of interest for an aggregate of trivial and non-trivial components: struct MyAggregate
{
std::string s;
int i;
};
int main()
{
auto defaultInitialized = new MyAggregate[2];
auto valueInitialized = new MyAggregate[2]();
return valueInitialized[0].i;
}
In this case, value-initialization takes care of zero-initializing the integer No need to adjust the text of the issue though, it's fine 👍 |
issakomi
added a commit
to issakomi/ITK
that referenced
this issue
Dec 5, 2023
Updated comments and the parameter 'UseValueInitialization' better describe the behavior of the ImportImageContainer. The same parameter in VectorImage has also been updated. Also removed comment from AllocateElements about 'new' and throwing or not throwing an exception if allocation fails. Closes InsightSoftwareConsortium#4359
N-Dekker
pushed a commit
that referenced
this issue
Dec 5, 2023
Updated comments and the parameter 'UseValueInitialization' better describe the behavior of the ImportImageContainer. The same parameter in VectorImage has also been updated. Also removed comment from AllocateElements about 'new' and throwing or not throwing an exception if allocation fails. Closes #4359
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This ( in itkImportImageContainer.h ) doesn't seem right to me
UseDefaultConstructor controls this:
C++03 value initialization with
()
is not about using a default constructor or not. A user-provided default constructor will be called in both cases, of course.The difference is for POD types (notation POD "plain old data" is, BTW, deprecated together with
std::is_pod
, actually it isstd::is_trivial<T>() && std::is_standard_layout<T>()
). For such types, e.g. scalars,()
will have effect of zero-initialization, the same as with C++11{}
.It is e.g. related to RGB images
itk::RGBPixel has a constructor
RGBPixel() { this->Fill(0); }
andimage->Allocate();
image->Allocate(true);
image->Allocate(false);
will make no difference, the default constructor will be always used (tested).
Again, for e.g. scalar types there is the effect of zero-initialization
int * x = new int[100]();
Any class with a use-provided default constructor, even the simplest one, is no longer trivial
I would suggest to make STYLE changes, remove the part about the "default constructor" from the comment and rename the variable UseDefaultConstructor to UseValueInitialization.
CC @N-Dekker
Edit:
For completeness, in the above example
A * a = new A[2]()
orA * a = new A[2]{}
does not initializex
, no difference withA * a = new A[2]
, but for B and C (trivial types)B * b = new B[2]()
orB * b = new B[2]{}
does initializex
to 0. Tested with Valgrind.The text was updated successfully, but these errors were encountered: