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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:53:43+00:00 2026-06-16T16:53:43+00:00

I’m writing some big data software that needs to hold a lot of data

  • 0

I’m writing some “big data” software that needs to hold a lot of data in memory. I wrote a prototype in c++ that works great. However the actual end-users typically code in Java so they’ve asked me to also write a java prototype.

I’ve done background reading on memory-footprint in java and some preliminary tests. For example, lets say I have this object

public class DataPoint{

    int cents, time, product_id, store_id;

    public DataPoint(int cents, int time, int product_id, int store_id){
    this.cents = cents;
    this.time = time;
    this.product_id = product_id;
    this.store_id = store_id;
    }
}

In C++ the sizeof this structure is 16 bytes, which makes sense. In Java we have to be indirect. If I create, e.g., 10m of these objects and use Runtime.totalMemory() – Runtime.freeMemory() before
and after and then divide as appropriate I get approximately 36 bytes per structure. A ~2.4x memory difference is pretty nasty; its gonna get ugly when we try to hold hundreds of millions of DataPoints in memory.

I read somewhere that in cases like this in Java its better to store the data as arrays — essentially a column-based store rather than a row-based store. I think I understand this: the column-based way reduces the number of number of references, and perhaps the JVM can even pack the ints into 8-byte words intelligently.

What other tricks can I use for reducing the memory-footprint of what is essentially a memory block that has one very large dimension (millions/billions of datapoints) and one very small dimension (the O(1) number of columns/variables)?

Turns out storing the data as 4 int arrays used exactly 16 bytes per entry. The lesson: small objects have nasty proportional overhead in java.

  • 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-06-16T16:53:44+00:00Added an answer on June 16, 2026 at 4:53 pm

    It isn’t that straightforward to see how much memory your data structure takes in Java. totalMemory() shows the space allocated for vm which is larger than the actual usage. You could try using Java profiler that shows space-consumption of your data structures, they are quite easy to setup and run. One handy free tool is Java’s own VisualVM that for example shows memory behaviour of your application, you will also learn a bit about how Java’s GC works if you use it.

    VisualVM screenshot showing performance footprint (image from http://visualvm.java.net/features.html):
    enter image description here

    You should also consider making the variables final if it’s possible. It allows Java VM to optimize the code bit better (not sure if it saves space though).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.