Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:17:11+00:00 2026-06-10T11:17:11+00:00

I’m building a app and I need to handle a position in a graph.

  • 0

I’m building a app and I need to handle a position in a graph. This position have value of X, Y and the direction like north, east, south and weast. I think this position could be a Struct because its represent a single value in that graph.

I researched and thought about Structs and find these rules to use a Struct:

  • It logically represents a single value, similar to primitive types
    (integer, double, and so on).
  • It has an instance size smaller than 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

Here’s an example of my unfinished Struct:

public struct Position
{
   public long PositionX { get; set; }

   public long PositionY { get; set; }

   public CompassPoint CompassPoint { get; set; }
}

public enum CompassPoint : byte
{
   North,
   East,
   South,
   West
}

I want to know how to calculate the size in bytes of my Struct and how I’ll know if it is immutable?

Thanks.

Update:

Okay. According to the responses it seems that my Struct passed the 16 bytes because only two long have 16 bytes + 1 byte of CompassPoint.

But an extra question would be: What I gained have using a Struct with 16 bytes and immutable? And look at DateTime Struct, it seems have more thatn 16 bytes? Any problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:17:12+00:00Added an answer on June 10, 2026 at 11:17 am

    The size depends on what the CompassPoint type is. However, each long will use 8 bytes, so you are already over the recommended maximum of 16 bytes. It’s not a hard rule though, but you may get worse performance than if it was a class, depending on how you use it.

    The exact size of the struct is determined by the JIT compiler, but genreally you can just add the sizes of the members to predict the size. Small data types will be padded though, so if your CompassPoint uses just a single byte, it will still require 4 or 8 bytes to make the struct size reach an even boundary.

    The struct is not immutable, as you can change the properties in it. Make the setters private, and add a constructor that can create it to make it immutable:

    public struct Position {
    
      public long PositionX { get; private set; }
      public long PositionY { get; private set; }
      public CompassPoint CompassPoint { get; private set; }
    
      public Position(long x, long y, CompassPoint compass) {
        PositionX = x;
        PositionY = y;
        CompassPoint = compass;
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.