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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:22:05+00:00 2026-05-12T16:22:05+00:00

If int is enough for a field, and if I use long for some

  • 0

If int is enough for a field, and if I use long for some reason, would that cost me more memory?

  • 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-12T16:22:05+00:00Added an answer on May 12, 2026 at 4:22 pm

    In Java, yes, a long is 8 bytes wide and an integer is 4 bytes wide. This Java tutorial goes over the primitive data types. If you multiply the number of allocations by a certain amount (say, if you’re allocating five million of these variables), the difference becomes more than negligible. For the average usage, however, it doesn’t matter as much.

    (You’re already using Java, memory’s kind of all over the place anyway.)

    In native languages, there’s a performance consideration; a 32-bit value can be held in a single register on a 32-bit architecture but not a 64-bit value; on 64-bit architectures, obviously, it can. I’m not sure what kind of optimization Java does on its native integers, but this might be true in its runtime as well. There’s alignment issues to worry about, as well — you see this more with using shorts and bytes, though.

    Best practice would be to use the type you need. If the value will never be over 2^31, don’t use a long.

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

Sidebar

Related Questions

I recently ran across a class that had the following field declared: private final
I have a table with two very important fields: id INT identity(1,1) PRIMARY KEY
For a class whose fields are solely primitive, ex.: class Foo { int a;
Using Moose, is it possible to create a builder that builds multiple attributes at
I'd like to say int x = magic(), y = moremagic(); return i =>
I have a strange problem with my query trying to join 3 tables. The
I have searched S.O. for this answer and have came close to an answer
I have a fairly simple table (forgive errors / stupidity, I'm still learning. Written
I was given this source code and asked to compile it: it fails with
Let me start by saying I have looked at many similar questions asked, but

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.