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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:42:27+00:00 2026-06-02T13:42:27+00:00

In an application of mine, I need a large constant (actually static readonly )

  • 0

In an application of mine, I need a large constant (actually static readonly) array of objects. The array is initialized in the type’s static constructor.

The array contains more than a thousand items, and when the type is first used, my program experiences a serious slowdown. I would like to know if there is a way to initialise a large array quickly in C#.

public static class XSampa {
    public class XSampaPair : IComparable<XSampaPair> {
        public XSampaPair GetReverse() {
            return new XSampaPair(Key, Target);
        }
        public string Key { get; private set; }
        public string Target { get; private set; }
        internal XSampaPair(string key, string target) {
            Key = key;
            Target = target;
        }
        public int CompareTo(XSampaPair other) {
            if (other == null)
                throw new ArgumentNullException("other", 
                        "Cannot compare with Null.");
            if (Key == null)
                throw new NullReferenceException("Key is null!");
            if (other.Key == null)
                throw new NullReferenceException("Key is null!");
            if (Key.Length == other.Key.Length)
                return string.Compare(Key, other.Key, 
                        StringComparison.InvariantCulture);
            return other.Key.Length - other.Key;
        }
    }    
    private static readonly XSampaPair[] pairs, reversedPairs;
    public static string ParseXSampaToIpa(this string xsampa) {
        // Parsing code here...
    }
    public static string ParseIpaToXSampa(this string ipa) {
        // reverse code here...
    }
    static XSampa() {
        pairs = new [] {
            new XSampaPair("a", "\u0061"), 
            new XSampaPair("b", "\u0062"),
            new XSampaPair("b_<", "\u0253"), 
            new XSampaPair("c", "\u0063"),
            // And many more pairs initialized here...
        };
        var temp = pairs.Select(x => x.GetReversed());
        reversedPairs = temp.ToArray();
        Array.Sort(pairs);
        Array.Sort(reversedPairs);
    }
}

PS: I use to array to convert X-SAMPA phonetic transcription to a Unicode string with the corresponding IPA characters.

  • 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-02T13:42:29+00:00Added an answer on June 2, 2026 at 1:42 pm

    You can serialize a completely initialized onject into a binary file, add that file as a resource, and load it into your array on startup. If your constructors are CPU-intensive, you might get an improvement. Since your code appears to perform some sort of parsing, the chances of getting a decent improvement there are fairly high.

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

Sidebar

Related Questions

Mine is an asp.net mvc application. I have an index view with rows more
I need to develop WCF services for an application of mine. I am aware
Just tried some small graphics application of mine on Windows 7, and I'm getting
I'm currently redesigning a old application of mine. I'm unsure in which form to
I have Application X (not mine!) with Subform x1, x2, x3. How can I
I am having UIAlertview with UITextField in that.Mine is iPad application -(void)showAlertToAddLink { alertToAddLink
I have a server application that consists of multiple OSGi bundles, some mine, some
I have a web application that I am hosting, and a client of mine
For my android application, I need to change the textChangedListener each time a RadioButton
I'm developing a sort of web application and recently come a need to log

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.