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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:39:08+00:00 2026-06-13T13:39:08+00:00

Java virtual machines may use int -sized width for short fields as well (this

  • 0

Java virtual machines may use int-sized width for short fields as well (this depends on their internal implementation). Only the arrays (short[]) are exception, where it is always guaranteed that they take less space than an int[] internally as well). What about Dalvik?

E.g. I have a class which contains 50 fields of type short. Sometimes in my application, 10000 of these classes exist. This means that the short fields should use 1MB of memory, but if Dalvik uses 4 bytes for short values internally, then this will be 2MB memory usage.

How much memory should I expect Dalvik to use? (This refers to its internal memory use, and I’m aware of the fact that it might not be reflected by the system memory usage, e.g. because Dalvik already reserved a higher amount of memory from the system.)

  • 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-13T13:39:09+00:00Added an answer on June 13, 2026 at 1:39 pm

    In dalvik, double and long fields are 8 bytes, everything else (including short) is 4 bytes.

    On the other hand, short arrays take 2 bytes per element (in addition to up-front space for the array+object bookkeeping).

    Arrays

    The new-array opcode calls dvmAllocArrayByClass (line 71) to allocate space. This then calls dvmAllocPrimitiveArray (line 113). In the switch in dvmAllocPrimitiveArray, the ‘S’ case is used for a short array. You can see it calls allocArray (line 38) with width=2.

    Within allocArray, it does the following computation to calculate the size size of the array:

    size_t elementShift = sizeof(size_t) * CHAR_BIT - 1 - CLZ(elemWidth);
    size_t elementSize = length << elementShift;
    size_t headerSize = OFFSETOF_MEMBER(ArrayObject, contents);
    size_t totalSize = elementSize + headerSize;
    

    For a short, on a 32 bit system, this calculation would be:

    size_t elementShift = (4 * 8) - 1 - 30; //== 1;
    size_t elementSize = length << 1; //i.e. length * 2
    size_t headerSize = <some constant value>;
    size_t totalSize = length*2 + <some constant value>;
    

    Short arrays take 2 bytes per element.

    Fields

    The new-instance opcode calls dvmAllocObject (line 181) to allocate space for the new object. The size that is allocated is based on the objectSize field of ClassObject. objectSize is set in computeFieldOffsets (line 3543). If you find every instance of where fieldOffset is incremented in this function, you will notice it is always incremented in steps of 4 bytes.

    Short fields take 4 bytes.

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

Sidebar

Related Questions

The Java Virtual Machine supports several garbage collection strategies. This article explains them. Now
Class.forName(boolean.class.getName()); This doesn't work in Java - the virtual machine slaps you with a
I was reading this question to find out the differences between the Java Virtual
If hardware support is a must for virtualization, how can Java Virtual Machines run
I'm new to modern Java compilers and Virtual Machines, so I'm curious, what technical
The Java Virtual Machine Instruction Set page provides information about mnemonics such as aaload,
Is the Java Virtual Machine really a virtual machine in the same sense as
I am reading Java Virtual Machine Specification second edition for Java 6. But I
I'm reading Programming for Java Virtual Machine by Joshua Engel book where the author
A previously working Ecplise now gives me the error Java Virtual Machine Launcher Could

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.