Outline ·
[ Standard ] ·
Linear+
buffer as byte[1024 * 4] from websocket message, reason behind?
|
TSragk
|
Jun 2 2022, 03:30 PM, updated 4y ago
|
|
I'm researching on raw websocket implementation recently, from multiple example I found they are all buffering the message with the same size byte [1024 * 4], is anyone know the reason behind this? Is this a recommended standard size? And is that any circumstance where I should reduce or increase this size? This post has been edited by ragk: Jun 2 2022, 03:57 PM
|
|
|
|
|
|
15cm
|
Jun 2 2022, 05:36 PM
|
|
did you mean 1024 or 4 ?
1024 is a meaningful number in software engineering because its 4x256 and 2x512
256 is 2 to the power of 8.
2 because computer uses a a base 2 calculation method (1 and 0 ) and 8 because 1 byte is made up of 8 bits
|
|
|
|
|
|
TSragk
|
Jun 2 2022, 05:58 PM
|
|
QUOTE(15cm @ Jun 2 2022, 05:36 PM) did you mean 1024 or 4 ? 1024 is a meaningful number in software engineering because its 4x256 and 2x512 256 is 2 to the power of 8. 2 because computer uses a a base 2 calculation method (1 and 0 ) and 8 because 1 byte is made up of 8 bits Both, it end up with buffer size of 4096, just want to have more understanding about it, is this a buffer figure that I should adjust according to my scenario (let say that's some, which I dunnoe what yet) or this should always be a standard figure? This sound like the max received message size it would accept through the socket? I'm not very familiar with low level design, should this be something configurable? Or the figure could be higher and it won't break any low level message transmission.
|
|
|
|
|
|
scar_face008
|
Jun 2 2022, 07:15 PM
|
|
max size is 1mb, probably by standard implementation. dunno why *4, probably to accomodate client as most are using that setup.
if you're response size is fixed, just change to accomodate it. otherwise if response size is unknown, just leave to default?
|
|
|
|
|
|
FlierMate1
|
Jun 2 2022, 09:15 PM
|
Getting Started

|
A little off topic, don't know about websocket, but 4096 (0x1000) is the size of memory page in my Linux ELF loader, means each segment has to be aligned to 4KB.
|
|
|
|
|
|
flashang
|
Jun 3 2022, 12:49 AM
|
|
QUOTE(scar_face008 @ Jun 2 2022, 07:15 PM) max size is 1mb, probably by standard implementation. dunno why *4, probably to accomodate client as most are using that setup. if you're response size is fixed, just change to accomodate it. otherwise if response size is unknown, just leave to default? byte[1024 * 4] is 4kb for data buffer, which should be enough for most cases. you could use different size, it really depends on how you transfer your data.
|
|
|
|
|
|
Lord Tiki Mick
|
Jun 4 2022, 10:38 PM
|
|
4kB is too big for websocket if you ask me. Usually basic websocket communication is only withing few dozens bytes. 1kB = 1024 should be more than sufficient. 😌
|
|
|
|
|
|
TSragk
|
Jun 7 2022, 10:35 AM
|
|
Thanks for clarify guy!
|
|
|
|
|
|
silverhawk
|
Jun 8 2022, 03:12 AM
|
Eyes on Target
|
|
|
|
|
|
|
FlierMate
|
Jun 15 2023, 08:50 PM
|
|
I finally understand why 4KB, because it is the minimum CPU memory page size, 4096 bytes. Page size is usually determined by the processor architecture. Traditionally, pages in a system had uniform size, such as 4,096 bytes. And Computer memory is divided into pages so that information can be found more quickly.https://en.wikipedia.org/wiki/Page_(computer_memory)
|
|
|
|
|