Re: ThreadMXBean.getThreadAllocatedBytes() allocates memory

2016-09-19 Thread Bengt Rutisson
Hi Claes and David, Thanks for the quick responses! Yes, a pre-allocated array is probably not the way to go. Letting the user pass a result array is much better or just specialising the "long getThreadAllocatedBytes(long id)" to avoid allocations instead of re-using the "long[]

Re: ThreadMXBean.getThreadAllocatedBytes() allocates memory

2016-09-18 Thread David Holmes
Hi Bengt, On 19/09/2016 7:14 AM, Bengt Rutisson wrote: Hi Serviceability, Not sure, but I hope this is the correct list to post this on. Sure is. I wanted to use the ThreadMXBean.getThreadAllocatedBytes() method to get some information about how much memory some Java code allocated. When

Re: ThreadMXBean.getThreadAllocatedBytes() allocates memory

2016-09-18 Thread Claes Redestad
Hi Bengt, I'm not Serviceability, but you know I can't leave them micro- optimizations alone! :-) So, reusing cached arrays could be made to work but would require some synchronization to keep things thread-safe and tidy[1]. This will complicate the code, especially since there's another