<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Aptos",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#467886;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-CA" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">First, thank you to those who replied and to those who may still reply. Let me apologize for neglecting the last 25+ years of hardware design.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">From what you have written or had on your blog, the issue of how much RAM a data type consumes, is not significant, at least to someone just starting their programming career. Back in my C/C++ days in the 1990s I worked on the assumption
 that for performance reasons your preferred data types were  the word size of your CPU, like an int, because, and it could likely be because I misunderstood what was happening in the hardware, a program ran faster if you used, say, an int.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I had not planned to get into these details on what I am working on but this morning I thought there might be some value to knowing precisely how primitive types consume memory. I think I will just stick with explaining what a stack and
 a heap are. I don’t think someone learning Java, it is a textbook I am writing,  would gain any insight into coding knowing how data is laid out in RAM. Correct me if I am wrong.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks again,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Ken<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:EN-CA">From:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:EN-CA"> discuss
 <<a href="mailto:discuss-retn@openjdk.org">discuss-retn@openjdk.org</a>> <b>On Behalf Of
</b>Kenneth Fogel<br>
<b>Sent:</b> August 8, 2025 12:11 PM<br>
<b>To:</b> <a href="mailto:discuss@openjdk.org">discuss@openjdk.org</a><br>
<b>Subject:</b> Memory Usage in Java<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">Please let me know where I might ask this question or find the answer if this is not the right place.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">In a book I am working on I am writing about how Java deals with memory allocation for the primitive types on a 64 bit CPU. I know the size of primitive variable types such as byte is 1, int is 4, etc. and that the size
 is related to the range of allowable values. From my C/C++ days I learned that the actual amount of RAM used was related to the word size of a CPU so that when a byte is read you are really reading a word. This meant to me that if I had 10 variables of type
 byte, not in an array, it would consume 80 bytes of RAM. From my reading it appears to be the same in Java except for arrays. Is this accurate? For example, an int is 4 bytes but when Java runs on a 64 bit CPU is it really reading and writing 8 bytes? If it
 is, can we say that the 4 bytes of padding is RAM dead space that cannot be used for anything else?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thank you for your time,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Ken Fogel<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:EN-CA">From:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:EN-CA"> discuss
 <discuss-retn@openjdk.org> <b>On Behalf Of </b>Kenneth Fogel<br>
<b>Sent:</b> August 8, 2025 12:11 PM<br>
<b>To:</b> discuss@openjdk.org<br>
<b>Subject:</b> Memory Usage in Java<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">Please let me know where I might ask this question or find the answer if this is not the right place.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">In a book I am working on I am writing about how Java deals with memory allocation for the primitive types on a 64 bit CPU. I know the size of primitive variable types such as byte is 1, int is 4, etc. and that the size
 is related to the range of allowable values. From my C/C++ days I learned that the actual amount of RAM used was related to the word size of a CPU so that when a byte is read you are really reading a word. This meant to me that if I had 10 variables of type
 byte, not in an array, it would consume 80 bytes of RAM. From my reading it appears to be the same in Java except for arrays. Is this accurate? For example, an int is 4 bytes but when Java runs on a 64 bit CPU is it really reading and writing 8 bytes? If it
 is, can we say that the 4 bytes of padding is RAM dead space that cannot be used for anything else?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thank you for your time,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Ken Fogel<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</body>
</html>