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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:10:54+00:00 2026-05-14T19:10:54+00:00

I have performance issues in this code segment which I think is caused by

  • 0

I have performance issues in this code segment which I think is caused by the “new Font”.

Will it be faster if fonts are static/global ?

if (row.StartsWith(TILD_BEGIN))  
{
    rtbTrace.SelectionColor = Color.Maroon; 
    rtbTrace.SelectionFont = new Font(myFont, (float)8.25, FontStyle.Regular);

    if (row.StartsWith(BEGIN) ) 
        rtbTrace.AppendText(Environment.NewLine + row + Environment.NewLine);
    else
        rtbTrace.AppendText(Environment.NewLine + row.Substring(1) 
            + Environment.NewLine);

    continue;
}

if (row.StartsWith(EXCL_BEGIN))
{
    -- similar block
}

if (row.StartsWith(DLR_BEGIN))
{
    -- similar block
}
.
.
.
  • 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-14T19:10:55+00:00Added an answer on May 14, 2026 at 7:10 pm

    If you can avoid ‘new’ every time you do this operation, then it will be faster. So if you repeat this operation many times and the font does not change, you should refactor the creation of the font into a different location.

    • If your code is in a loop (it looks this way, as you have continue; in it, then you can ‘new’ the font once just outside the loop so it is initialised once instead of once-per-loop-iteration.
    • If the code is in a method that is called many times, then you can add a Font member variable to your class and ‘new’ it with a default value, or in the constructor or an initialisation method.
    • If you create and destroy many instances of the class that is doing this work, then you can make the font a static member so it is only initialised once for each execution of your application – again you can initialise it with a default value, or in a static constructor or initialiser method.

    (Alternatively, in the last two cases, if there are times when you might not need to use the font at all, then you can initialise the font variable to null, and then do a lazy “just in time” creation by checking if (font == null) font = new Font(...); just before any code that needs to use it, so it is only created once, but it isn’t created at all if not needed).

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

Sidebar

Ask A Question

Stats

  • Questions 427k
  • Answers 427k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since v2.5, WordPress has used phpass over md5() for storing… May 15, 2026 at 12:57 pm
  • Editorial Team
    Editorial Team added an answer I recommend you to use Red-Dwarf for the server and… May 15, 2026 at 12:57 pm
  • Editorial Team
    Editorial Team added an answer Do you get a header in your response that says… May 15, 2026 at 12:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.