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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:51:48+00:00 2026-05-24T06:51:48+00:00

What is additional memory cost of Tuple[Int, Int] ie. (1, 2) over two Ints

  • 0

What is additional memory cost of Tuple[Int, Int] ie. (1, 2) over two Ints without Tuple ?

  • 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-24T06:51:49+00:00Added an answer on May 24, 2026 at 6:51 am

    JVM overheads tend to be 16 to 24 bytes per object (32-bit and 64-bit respectively, though compressed pointers can make the latter smaller). Tuple2 is specialized on Int, which means it stores the values in fields, so you have 8 bytes for two ints as compared to 8+16=24 or 8+24=32 for (1,2). If you use a similar non-specialized collection (or use Tuple2 for something that it is not specialized on, like Char), then you need pointers to objects, and you may need the objects depending on whether they can be pre-allocated (arbitrary integers, no; arbitrary bytes, yes; arbitrary chars, maybe). If yes, then you just need the pointer and it’s 8+16=24 or 16+24=40 bytes; if no, you need three objects, so it’s 16+8+2*(16+4) = 64 and 24+16+2*(24+4) = 96 respectively.

    Bottom line: objects use a lot more memory than primitive types, usually 3-4x, but sometimes over 10x. If you are short on memory, pack as much as you can into arrays. For example:

    Bad for memory usage:

    val a = (1 to 10000).map(x => (x,x.toString.length)).toArray
    

    Good for memory usage:

    val b = ((1 to 10000).toArray, (1 to 10000).map(_.toString.length).toArray)
    

    If you’re really tight on memory, you can then write iterators and other wrappers that let you index things as if they were an array of tuples instead of a tuple of arrays. It’s a bit of a pain, but if you’re really short on memory it can be worth it.

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

Sidebar

Related Questions

Additional thanks extend to Daniel Newby for answering my memory usage question (and Martin
I am able to load over 200 UIImage objects into a NSMutableDictionary without any
I read an article that says memory allocated on heap needs additional memory for
At memory 0x100 and 0x104 are two 32-bit counters. They represent a 64-bit timer
This question concerns memory in Android. My method: I have two activites, A and
Additional questions regarding SilentGhost's initial answer to a problem I'm having parsing Twitter RSS
I need to display additional information, like a tooltip, but it's a lot of
how do I pass additional information to the service method returning the collection of
Is there some additional configuration needed before I can set thread priorities in a
are there any additional WPF themes from microsoft except that default ones provided in

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.