I am allocating a netty ByteBuf which offers the clear() method.--Such buffer needs to be wrapped with new Buffer() in order to be used.Do you think this is the right approach? I didn't find anything in the documentation.
On Thursday, January 8, 2015 at 4:23:44 PM UTC+1, Matteo Spennati wrote:Hello,
Can I clear a Buffer instance to reuse it? if yes, how?
Matteo.
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I want to recycle the Buffer after each time I send a packet otherwise it would keep expanding forever isn't it?
I would like to clear the indexes and reuse it like I would do in Netty
or XNIO, without producing too garbage for the collector.This is a draft of what I do at the moment, send buffer is a Netty direct buffer.
while(true) {sendBuffer.clear();sendBuffer.writeBytes(...);
sock.write(new Buffer(sendBuffer));
Ok but then my code is working by chance..., I clear such before I reuse it. Then I can't assume that after the write my data is "copied out"... :-\
Ok i changed my code and rather use the netty buffer pool, then wrap such buffer with vertx Buffer.