Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 buffer as byte[1024 * 4] from websocket message, reason behind?

views
     
TSragk
post Jun 2 2022, 03:30 PM, updated 4y ago

BooBoo~
*******
Senior Member
2,354 posts

Joined: Apr 2009


Attached Image
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
post Jun 2 2022, 05:36 PM

Casual
***
Junior Member
423 posts

Joined: Apr 2022
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
post Jun 2 2022, 05:58 PM

BooBoo~
*******
Senior Member
2,354 posts

Joined: Apr 2009


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
post Jun 2 2022, 07:15 PM

opis boi
****
Senior Member
590 posts

Joined: Jan 2007
From: Ranau, Sabah


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
post Jun 2 2022, 09:15 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
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
post Jun 3 2022, 12:49 AM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


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.

smile.gif


Lord Tiki Mick
post Jun 4 2022, 10:38 PM

Regular
******
Senior Member
1,020 posts

Joined: Jul 2012
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
post Jun 7 2022, 10:35 AM

BooBoo~
*******
Senior Member
2,354 posts

Joined: Apr 2009


Thanks for clarify guy!
silverhawk
post Jun 8 2022, 03:12 AM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


https://stackoverflow.com/questions/3033771...ory-buffer-size
FlierMate
post Jun 15 2023, 08:50 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
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)

biggrin.gif



 

Change to:
| Lo-Fi Version
0.0183sec    1.33    6 queries    GZIP Disabled
Time is now: 23rd December 2025 - 06:53 PM