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

  • Home
  • SEARCH
  • 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 7002213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:53:59+00:00 2026-05-27T20:53:59+00:00

I am currently looking at this: some Genetic Algorithm This is some adapted code:

  • 0

I am currently looking at this:

some Genetic Algorithm

This is some adapted code:

struct Chromosome
{
    public bool[] genes;
    public int fitness;
}

I have never used structs in my evolutionary algorithms/genetic algorithms. Is it not a bit pointless to use arrays in structs – especially when I have to make deep copies? Is there any advantage of using structs in this scenario?

Thanks.

  • 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-27T20:53:59+00:00Added an answer on May 27, 2026 at 8:53 pm

    Typically, we use a struct to represent something that can be considered pretty primitive. According to MSDN, it should be a type that represents a single “value”, 16 bytes or less in size, and so on.

    The main thing to keep in mind with a struct is the value-type semantics, so passing this in and out of functions will create a copy. Cost wise this won’t be too bad since what you are copying is 1 reference (to the array of bool) and 1 int, but it does create some interesting side effects if you try to modify the array reference in another method or from a copy.

    Many people assume struct will always be more efficient than class, but this is not always the case and usually this micro-optimization is more dangerous than helpful because it introduces the side-effects of working with a value type.

    As for the array of bool you can either create and set bits in an int or use the BitArray specialized class in the BCL.

    So, the long and the short of it is, if this is legacy code and you want to keep the struct, it will work, but it can byte you if you expect it to act like a class does when passed/copied. However, looking at what it’s holding, it doesn’t meet the MSDN guidance for what struct is best suited for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I'm looking for some input, I'm pretty sure this is not currently supported
I'm looking at some code with this form: 1 package com.stackoverflow.java.questions; 2 import java.util.ArrayList;
I am currently looking at some code which basically reads data line-by-line from a
We are currently looking to adopt some type of standard developer framework and have
I'm looking to add some genetic algorithms to an Operations research project I have
I am currently looking into socket programming in python and I am experiencing some
I'm currently refactoring some code the explicitly specializes a member function of a class
I am currently looking at upgrading a gem to Rails 3, some work has
Sorry if this sounds simple, but I'm looking for some help to improve my
[Frontmatter] (skip this if you just want the question) : I'm currently looking at

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.