question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use union for DreamValue

See original GitHub issue

Using a union would allow you to avoid all boxing operations with DreamValue. Layout would look something like this:

[StructLayout(LayoutKind.Explicit)]
struct DreamValue
{
    [Flags]
    public enum DreamValueType : byte {
        String = 1,
        Integer = 2,
        Float = 4,
        Number = Integer | Float,
        DreamResource = 8,
        DreamObject = 16,
        DreamPath = 32,
        DreamProc = 64
    }

    [FieldOffset(0)]
    public DreamValueType Type { get; private set; }
    [FieldOffset(4)]
    public float FloatValue { get; private set; }
    [FieldOffset(4)]
    public int IntValue { get; private set; }
    [FieldOffset(8)] 
    public object RefValue { get; private set; }

    public DreamValue(String value)
    {
        Unsafe.SkipInit(out this);
        RefValue = value;
        IntValue = default;
        Type = DreamValueType.String;
    }

    public DreamValue(int value)
    {
        Unsafe.SkipInit(out this);
        RefValue = default;
        IntValue = value;
        Type = DreamValueType.Integer;
    }

    public DreamValue(int value)
    {
        Unsafe.SkipInit(out this);
        RefValue = default;
        FloatValue = value;
        Type = DreamValueType.Float;
    }

    public DreamValue(UInt32 value) : this((int) value)
    {
    }
}

It does beg the question though: why do you allow storing an int in DreamValue? It’s not a real data type in DM and it sounds like it would only complicate the code. This wouldn’t be necessary if DreamValue stores only floats.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ike709commented, May 17, 2021

@ZeWaka since you were looking into boxing memes

0reactions
wixoaGitcommented, Feb 3, 2023

The idea of making DreamValue into a union is no longer relevant since these are now the only two fields on it, and boxing is not as much of a concern anymore.

private object? _refValue;
private readonly float _floatValue;
Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL UNION overview, usage and examples
This article will provide a deep dive into the SQL Union operator, describing its many uses along with examples and explore some common ......
Read more >
Northern Inland Credit Union Dream Value Home Loan - Mozo
Looking to get more information on the Northern Inland Credit Union Dream Value Home Loan? Find all the product details, interest rates, real...
Read more >
Dream Value Home Loan
This home loan package includes all the important features – no establishment fee, 100% offset account and a discounted rate off the standard...
Read more >
UNION, INTERSECT, and EXCEPT - Amazon Redshift
The UNION, INTERSECT, and EXCEPT set operators are used to compare and merge the results of two separate query expressions. For example, if...
Read more >
Use a union query to combine multiple queries into ...
Get a combined view of multiple select queries with a union query. ... You can't create or use a union query in Access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found