Actually you want to call ByteBuf.retainedDuplicate() as you also need to increment the reference count.
> On 12. Apr 2019, at 08:19, Frederic <[email protected]> wrote: > > You can create one buffer and then use to send to all your sockets the very > same buffer content but using different indexes (read here) using the > ByteBuf.duplicate() method. > > https://netty.io/4.1/api/io/netty/buffer/ByteBuf.html#duplicate-- > > Javadoc says: > > public abstract ByteBuf > <https://netty.io/4.1/api/io/netty/buffer/ByteBuf.html> duplicate() > Returns a buffer which shares the whole region of this buffer. Modifying the > content of the returned buffer or this buffer affects each other's content > while they maintain separate indexes and marks. This method does not modify > readerIndex or writerIndex of this buffer. > The reader and writer marks will not be duplicated. Also be aware that this > method will NOT call retain() > <https://netty.io/4.1/api/io/netty/buffer/ByteBuf.html#retain--> and so the > reference count will NOT be increased. > > Returns: > A buffer whose readable content is equivalent to the buffer returned by > slice() <https://netty.io/4.1/api/io/netty/buffer/ByteBuf.html#slice-->. > However this buffer will share the capacity of the underlying buffer, and > therefore allows access to all of the underlying content if necessary. > > Le vendredi 12 avril 2019 06:31:57 UTC+2, [email protected] a écrit : > Are there any optimizations available if I'd like to send the very same data > to dozens (or hundreds) of Websocket channels? > At a minimum I'd like to avoid creating (and copying) the data to new > buffers. Ideally I would provide a single buffer and a list of channels. > > -- > You received this message because you are subscribed to the Google Groups > "Netty discussions" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/netty/4c93f31c-a1f0-48be-94ef-b7cda094e2c5%40googlegroups.com > > <https://groups.google.com/d/msgid/netty/4c93f31c-a1f0-48be-94ef-b7cda094e2c5%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Netty discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/netty/ACD55063-70A5-4D98-882B-BC3AEBE3B142%40googlemail.com. For more options, visit https://groups.google.com/d/optout.
