Skip to content
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

Container: Default initialization of elements #479

Open
devreal opened this issue Jan 12, 2018 · 1 comment
Open

Container: Default initialization of elements #479

devreal opened this issue Jan 12, 2018 · 1 comment

Comments

@devreal
Copy link
Member

devreal commented Jan 12, 2018

Consider the following code snippet:

  struct point_t {
    int x, y = 1;
  };

  std::vector<point_t> vec(N);
  assert(vec[0].y == 1); // succeeds

  dash::Array<point_t> arr(N);
  assert(vec[0].y == 1); // may or may not succeed

Point to make: Contrary to the STL, elements in DASH container are not initialized with their default value. Now, there is a good argument for this: performance! Many times users might want to skip implicit initialization because they perform the initialization themselves, e.g., using dash::fill.

However, since we aim to be compatible with STL behavior and because I tapped into this trap myself (see b67c065) I decided to raise this issue. What's more, this is mostly only relevant for derived types in DASH container because it is all too tempting to rely on the default values specified in the type definition.

As far as I can see this behavior is not documented anywhere.

Should we change the behavior to provide default initialization or make it optional (one way or another)? Or just document this deviation from the STL behavior?

@BenjaProg
Copy link
Member

BenjaProg commented Jan 12, 2018

Hey here some input from my side:
Wouldn't it be failsafer for new developer if it behaves like in STL?
I suggest offering a constructor without initialization for performance aware programmers.
Is this a option? Or am I fooling myself anywhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment