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

Switch to uint8_t, some optimizations #979

Merged
merged 8 commits into from
Oct 20, 2024
Merged

Switch to uint8_t, some optimizations #979

merged 8 commits into from
Oct 20, 2024

Conversation

davepl
Copy link
Contributor

@davepl davepl commented Oct 19, 2024

Description

Replace this text with your description.

Contributing requirements

  • I read the contribution guidelines in CONTRIBUTING.md.
  • I placed my solution in the correct solution folder.
  • I added a README.md with the right badge(s).
  • I added a Dockerfile that builds and runs my solution.
  • I selected drag-race as the target branch.
  • All code herein is licensed compatible with BSD-3.

davepl and others added 5 commits October 18, 2024 13:38
* Use latest Julia version to represent current performance (#972)

* Use latest Julia version to represent current performance

* Use latest stable 1.X version

* Add timeout to benchmark solution runs (#977)

* Added formatting and removed deprecated attributes syntax (#982)

Co-authored-by: Tudor Marghidanu <[email protected]>

---------

Co-authored-by: Christian Guinard <[email protected]>
Co-authored-by: Tudor Marghidanu <[email protected]>
Co-authored-by: Tudor Marghidanu <[email protected]>
Copy link
Contributor

@rbergen rbergen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always like improvements to one of the original solutions! :)

I have two comments, the second one (array initialization) is the one I think actually matters.

@@ -24,80 +24,66 @@ using namespace std::chrono;
const uint64_t DEFAULT_UPPER_LIMIT = 10'000'000LLU;

class BitArray {
uint32_t *array;
uint8_t *array;
size_t arrSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to declare arrSize as a member variable? It's private so only visible to the BitArray member functions, and I don't think it's used anywhere outside the constructor.

Comment on lines 46 to 47
// Bits are left at zero default, so no need to initialize them
// std::memset(array, 0x00, arraySize(arrSize));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you absolutely sure? When I was learning C++, it was hammered into me by my teacher that with C and C++, one has to assume garbage when allocating memory via new.

I actually looked up the documentation in the C++ reference, and this is what it says about default initialization, which is what's done when new T is used ("if T is an array type, every element of the array is default-initialized", as per Default-initialization):

When storage for an object with automatic or dynamic storage duration is obtained, the object has an indeterminate value.

If no initialization is performed for an object, that object retains an indeterminate value until that value is replaced.

It may work by accident in your office, but it looks to me we can't rely on that happening elsewhere. :)

@davepl
Copy link
Contributor Author

davepl commented Oct 20, 2024 via email

Copy link
Contributor

@rbergen rbergen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@rbergen rbergen merged commit 887109f into drag-race Oct 20, 2024
330 checks passed
@rbergen rbergen deleted the ibmstuff branch October 21, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants