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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:12:32+00:00 2026-05-20T01:12:32+00:00

In the help for XNA Vector3, two of the public methods that it lists

  • 0

In the help for XNA Vector3, two of the public methods that it lists are Subtract and op_Subtraction. What’s the difference between them and when should one be used instead of the other?

  • 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-20T01:12:33+00:00Added an answer on May 20, 2026 at 1:12 am

    op_Subtraction (the - operator implementation) and Vector3.Subtract are essentially the same thing. They create a new vector with values from a subtraction operation. Vector3 is a value type, so there is no memory-management cost, however there is a small construction cost.

    The other overload of Subtract is slightly different:

    void Vector3.Subtract(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
    

    This one takes references for its input and for its output. It is better for data-oriented programming (for example: a tight loop in, say, a physics engine, which takes data from one array and outputs it into another array). This removes the construction cost, and the cost of passing 6 floats as arguments, however there is still a tiny cost for the function call and dereferencing.

    You can get even faster by doing the subtraction directly:

    result.X = value1.X - value2.X;
    result.Y = value1.Y - value2.Y;
    result.Z = value1.Z - value2.Z;
    

    Of course, as you select faster options, you also lose readability! This is much clearer:

    result = value1 - value2;
    

    So to answer your question – you should absolutly use the vector - operator when doing vector subtraction, unless you’re writing some kind of very high-performance data-oriented thing and you have profiled your code and found it to be a worthwhile performance improvement.

    If you’re interested in more low-level performance information like this, take a look at Understanding XNA Framework Performance by Shawn Hargreaves. (In fact it includes a benchmark comparing the three methods I have listed here, when used in a particle system.)

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

Sidebar

Related Questions

HELP! I just setup a virtual host for two sites that have a lot
I've been asked to help out on an XNA project with the AI. I'm
Help! I have an Axis web service that is being consumed by a C#
In case it matters, I am using XNA 3.1, although if 4.0 would help
I have just started learning XNA. This is my first program that I am
Ever since I ported my game to Xbox with XNA the code that's supposed
I'm fooling around with the XNA framework. To help me around I made a
Help Help! Google indexed a test folder on my website which no one save
I'm writting this XNA game and in order to help me debug some problems,
http://www.cs.helsinki.fi/group/goa/viewing/leikkaus/intro.html This is the site that I'm using to help me implement Liang-Barsky into

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.