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

Why the size of OptoinalXxx.emty() is zero? #174

Open
sunriseLe opened this issue Jul 18, 2024 · 0 comments
Open

Why the size of OptoinalXxx.emty() is zero? #174

sunriseLe opened this issue Jul 18, 2024 · 0 comments

Comments

@sunriseLe
Copy link

  • In class SizeOf, I found the size of OptoinalXxx.emty() is zero. In my opinion, the size of empty instance should be OPTIONAL_INSTANCE_SIZE or OPTIONAL_INT_INSTANCE_SIZE.
  • Because it's an instance and will use basic memory for class layout
    public static <T> long sizeOf(Optional<T> optional, ToLongFunction<T> valueSize)
    {
        return optional != null && optional.isPresent() ? OPTIONAL_INSTANCE_SIZE + valueSize.applyAsLong(optional.get()) : 0;
    }
    
    
    public static long sizeOf(OptionalInt optional)
    {
        return optional != null && optional.isPresent() ? OPTIONAL_INT_INSTANCE_SIZE : 0;
    }
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

No branches or pull requests

1 participant