Allocating Buffer Memory

Top  Previous  Next

The wln. object requires a single buffer. This buffer is used to form outgoing packets and is necessary for correct operation. You never have to deal with this buffer directly — it is handled internally by the wln. object itself.

Buffer memory is allocated in pages. A page is 256 bytes of memory. Allocating memory for a buffer is a two-step process: First you have to request for a specific allocation (a number of pages) and then you have to perform the actual allocation. Request the size you need in pages using the wln.buffrq method.

The allocation method (sys.buffalloc) applies to all buffers previously specified, in one fell swoop:



Dim x As Byte

x = wln.buffrq(5) ' request 5 pages for the wln buffer. X will then contain how many can actually be allocated

' ....  Allocation requests for buffers of other objects...

sys.buffalloc 'perform actual memory allocation, as per previous requests



You may not always get the full amount of memory you have requested. Memory is not an infinite resource, and if you have already requested (and received) allocations for 95% of the memory for your platform, your next request will get up to 5% of memory, even if you requested for 10%.

Current wln. buffer size in bytes can always be checked with the wln.buffsize read-only property.

Note that wln buffer size can't be changed when the Wi-Fi hardware is already booted (wln.enabled= 1- YES).

How many pages should the wln buffer get?

The size of the wln buffer directly dictates the maximum size of network packets that the wln object will be able to send (this buffer has nothing to do with incoming packets). Up to 100 bytes of the buffer space are required for various packet headers, and the rest is available to packet payload. For example, if you have allocated 2 pages for the buffer, then the buffer size is 512 bytes. Hence, maximum payload size cannot exceed 412 bytes. That is, every TCP, UDP, etc. packet sent, including its protocol headers, will not exceed 412 bytes.

For TCP communications, the size of individual packets is not that critical. The beauty of TCP is that it can work with practically any buffer space available. in theory, the bigger the buffer, the better the TCP throughput is. In reality, you will stop feeling any improvement in TCP performance once your wln. buffer size exceeds ~3 pages. UDP is another matter entirely. If you want to be able to send UDP datagrams of a certain size, then you must make sure that you have created an adequate wln. buffer.

In any case, TiOS does not send out TCP or UDP packets with payloads exceeding 1024 bytes (4 pages). This is the internal limitation of TiOS iteself. Add to this TCP/UDP and Wi-Fi headers, and you are still within 5 pages. Therefore, there is no point in setting the wln. buffer to more than 5 pages.