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 7552359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:44:30+00:00 2026-05-30T10:44:30+00:00

We use struct in C# whenever possible mainly because it is stored on the

  • 0

We use struct in C# whenever possible mainly because it is stored on the stack and no objects are created for it. This boosts the performance.

On the other hand, arrays are stored on the heap.

My question is, if I include an array as an element of the struct, something as follows:

struct MotionVector
{
    int[] a;
    int b;
}

Then what will be the consequences. Will that array be stored on stack? Or the performance advantage of using struct will be lost?

  • 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-05-30T10:44:32+00:00Added an answer on May 30, 2026 at 10:44 am

    If you don’t want to create elements dynamically, consider to create a (big) buffer of MotionVector instances during startup and reuse those when needed. Then you will not get the penalty of creating/destructing them dynammically.

    Of course you have to write some small functions to get a ‘free’ instance and to obtain one, use a boolean in the struct for that (or by using an interface).

    To do this you could e.g.:

    Create during initialisation of your app the motionvectors:

    MotionVectors motionVectors;
    

    Add a boolean to the MotionVector class:

    public class MotionVector
    {
        bool InUse { get; set; }
    
        public MotionVector() 
        {
            InUse = false; 
        }
    }
    

    Define the new class MotionVectors:

    class MotionVectors
    {
        MotionVector _instances[100];
    
        public void Free(MotionVector vector)
        {
            var index = 'search vector in _instances' 
            _instances[index].Inuse = false;
        }
    
        public MotionVector GetNewInstance()
        {
            var index = 'first free vector in _instances'
            _instances[index].Inuse = true;
            return _instances[index];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my c++ struct (Use Multi-Byte Character Set) typedef struct hookCONFIG { int
I am aware of two possible ways to define and use struct s: #1
Possible Duplicates: When to use struct in C#? When should I use a struct
In what scenarios is it better to use a struct vs a class in
I want to use some basic struct in C like the following: struct p
I have a type which I consider use it as struct. It represents single
I have the following use case, a struct with some boolean and int variables
Hi I am trying to use C to implement a simple struct: 2 boxes,
MSDN says that you should use structs when you need lightweight objects. Are there
I'm constantly getting this error whenever I try to pass a array of Strucs

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.