arduinoWebSockets
arduinoWebSockets copied to clipboard
Use a buffer pool
I'm consistently sending large messages of the same size. It would be much more efficient to be able to reuse the payload buffer instead of a new one being malloc'd each time.
Hi, somthing like this is possible via the headerToPayload parameter,
with this you can skip all the internal copys by providing your data with the required free and unused space (at the beginning of the buffer) to add the websocket header directly to you buffer.
the WEBSOCKETS_MAX_HEADER_SIZE will tell you the size you need to reserver.
Thank you, I didn't realize this was possible!
Sorry, I should've clarified, I'm receiving messages, not sending. Is there a way to do this on the receive side? I didn't see one in the code.
for the ws header the lib uses a static buffer. https://github.com/Links2004/arduinoWebSockets/blob/30d5e136665a52880f641ddd7245b3ba05ecd32b/src/WebSockets.h#L327
but for the payload its malloc.
https://github.com/Links2004/arduinoWebSockets/blob/30d5e136665a52880f641ddd7245b3ba05ecd32b/src/WebSockets.cpp#L453-L462 https://github.com/Links2004/arduinoWebSockets/blob/30d5e136665a52880f641ddd7245b3ba05ecd32b/src/WebSockets.cpp#L522-L524
you can modify this in code.