java - Does using small datatypes reduce memory usage (From memory allocation not efficiency)? -


actually, question similar one, post focus on c# only. read article said java 'promote' short types (like short) 4 bytes in memory if bits not used, can't reduce usage. (is true ?)

so question how languages, c, c++ , java (as manish said in post talked java), handles memory allocation of small datatypes. references or approaches figure out preferred. thanks

c/c++ uses specified amount of memory aligns data (by default) address multiple of value, typically 4 bytes 32 bit applications or 8 bytes 64 bit.

so example if data aligned on 4 or 8 byte boundary "char" uses 1 byte. array of 5 chars use 5 bytes. data item allocated after 5 byte char array placed @ address skips 3 bytes keep correctly aligned.

this performance on processors. there pragmas "pack" , "align" can used change alignment or disable it.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -