4 ms·
Is that how languages that always give you zeroed arrays (e.g., java) do it?
by fyp 7y ago
Is that how languages that always give you zeroed arrays (e.g., java) do it?
- deleted 7y ago[deleted]
- NohatCoder 7y agoThere is no canonical answer to that question. Compilers wary wildly in implementation details.
- marcoperaza 7y agoI doubt it. Needing to zero ultra large chunks of memory often enough that you care about performance to this extent is a very niche scenario. If I had to guess, Java probably just zeroes the memory upon garbage collecting it or before handing it back out; fresh pages from the OS are already zeroed. But anything is possible. Maybe some big customer used this pattern and now Java detects it and does something fancy like what I suggested. But really, this is an unusual scenario for an application.
- MaxBarraclough 7y agoThere's a brilliantly-named paper on this: Why Nothing Matters: The Impact of Zeroing. Efficient zeroing is something JVMs put some thought into. Well, with a notable exception, in HotSpot itself: We were able to substantially improve its performance by using memset() to perform the zeroing. [0] (PDF) http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.225.9497&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.225...