213
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
sub
on_sys_init
net.ip=
"192.168.1.95"
sock.num=
0
sock.targetip=
"192.168.1.96"
'...and everything else that you may need!
end
sub
Buffer Management
How to allocate buffer memory
or
, rely on buffers for storing the data
being sent and received. For example, each serial port of the ser object has two
buffers- RX and TX, while each socket of the sock object has 6 different buffers.
By default, all buffers have no memory allocated for them, which basically means
that they cannot store any data. For related objects to work, these buffers need to
be given memory.
Memory is allocated in pages. Each page equals 256 bytes. There is a small
overhead for each buffer- 16 bytes are used for internal buffer houskeeping
(variables, pointers, etc.). Therefore, if you have allocated 2 pages for a particular
buffer, then this buffer's actual capacity will be 2*256-16= 496 bytes.
Buffer memory allocation is a two-step process. First, you request certain number
of pages for each port, socket, etc. that you plan to use. This is done through
methods of corresponding objects. For example, the
method
requests buffer memory for the RX buffer of one of the serial ports. Similar
methods exist for all other buffers of all objects that require buffer memory. Note,
that actual memory allocation does not happen at this stage- only your "requests"
are collected.
After all requests have been made actual memory allocation is performed by using
the
method. This allocates memory, as per previous requests, for
all buffers of all objects. Here is an example:
'allocate memory for RX and TX buffers of serial port 0 and socket 0
'make requests
ser.num=
0
ser.rxbuffrq=
5
ser.txbuffrq=
5
sock.num=
0
sock.rxbuffrq=
4
sock.txbuffrq=
4
'and now actual allocation
sys.buffalloc
Typically, buffer memory allocation is done in the on_sys_init event handler but
you don't have to do it this way. In fact, your application can re-allocate buffer
memory space according to the changes in the operating mode or other conditions.
Sys.buffalloc could take up to several hundred milliseconds to execute, so it makes
sense to use it as little as possible. Hence, request all necessary buffer allocations
first, then use the sys.buffalloc once to finish the job.
Buffer (re)allocation for a specific object will only work if the corresponding object
or part of the object to which this buffer belongs is idle. "Part" refers to a particular
274
224
262
217