I inherited some Java code that writes messages to a socket using local ByteBuffer:
ByteBuffer
public void sendMessage(){ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024); byteBuffer.clear(); byteBuffer.putInt((int) 128); }
It seems that the call is clear()not needed. Would it be guaranteed to return a freed memory block?
clear()
No need to call clear()after allocateDirect.
allocateDirect
What allocateDirect:
The new buffer position will be zero, its limit will be its capacity, its label will be undefined, and each of its elements will be initialized to zero.
What clear:
clear
, , .[..], , , , .
, ByteBuffer clear() ( , clear() reset ).
, ( ).
, , .
, , , , :
ByteBuffer FillBytes(ByteBuffer buf) { buf.clear(); //--- }
, , , , - , dev reset , , , (, - , , reset).