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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:16:53+00:00 2026-05-18T00:16:53+00:00

Say I have a triangle class, defined something like class Triangle{ vertex3D vertexs[3]; public:

  • 0

Say I have a triangle class, defined something like

class Triangle{
vertex3D vertexs[3];
public:
vertex* GetVertex(int vertexNumber);
}

now for most normal applications its fairly obvious that GetVertex should ensure that vertexNumber is a valid index before trying to return the vertex pointer. I would say that normally it can return NULL if vertexNumber is not valid, but that’s not really what I am asking about.

In a game situation, checking if vertexNumber is valid all the time could take up a fair bit of time, it would be quicker for GetVertex to assume that only valid values will be passed in.

So would it be acceptable for triangle to basically throw caution to the wind in the name of a slight performance boost?

If I do go for a bounds checking in debug but not release, how can I automate this so that I don’t have to edit the code? Some sort of compile time switch or something? would using #ifdef debug sort of stuff work? where can I find more about this?

  • 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-18T00:16:54+00:00Added an answer on May 18, 2026 at 12:16 am

    You should definitely check the bounds in a debug build.

    If you’re sure that your code is correct (so, you’ve had a code review and you’ve tested it extensively) then it is fine to leave out bounds checks in a release build for the sake of performance.

    If you are going to test the bounds in a debug build but not in a release build then you should probably use an assert in the debug build. asserts should be used to verify things that are always true. If you are not checking bounds inside of the function and your code is correct, then the value should never be out of bounds.

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

Sidebar

Related Questions

Say I have a class named Frog, it looks like: public class Frog {
Say I have a class Code defined like this, with a user specified type
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say I have a method like this: public void SaveData() { try { foreach
let say have element like this <div class=watch-me style=display: none;>Watch Me Please</div> as we
Say I have a Student table, it's got an int ID. I have a
Let's say I have an abstract parent class called shape, and that there are
Say I have a square from (0,0) to (z,z). Given a triangle within this
Say I have a method declaration like: private void someMethod(final String someKey, final Object
Say we have the following method: private MyObject foo = new MyObject(); // and

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.