Hello John,
Thanks for this heads-up on the SB memory allocator. However, don't let yourself be misguided based on that blurred and evasive description by Peter Verhas. What he is in fact describing here is a
classic pool allocator.
...................................
Using the package MyAlloc you i) first create a memory segment. A memory segment is a logical entity. Whenever you allocate a new piece of memory you have to specify what memory segment you want to use for it. ii) MyAlloc does not preallocate memory, just keeps track of the memory pieces that were allocated for the segment. Whenever you want to get rid of all memories allocated for a segment you can release them all with a iii) single function call without calling free for each malloced memory piece.
...................................
The module is GNU LGPL and is part of the ScriptBasic interpreter package.
(Coloration and italization is mine)
i) "Memory segment" in professional parlance here means a large
memory pool. It is allocated with
malloc() just once and no other malloc'ing for individual objects, strings, etc. takes place elsewhere in the code.
ii) MyAlloc does not preallocate memory for the
individual objects, strings, etc. It only preallocates it once for the entire memory pool and then just dispatches, and keeps track of, exactly what starting addresses and address ranges
within the pool are assigned to various objects, strings, etc. throughout the code. Whenever an object, string, etc. is no longer needed, the dispatcher simply marks its starting address and range as vacant.
iii) The single function call to
free() is made to deallocate the entire memory pool whenever there are no objects, strings, etc. left in it. If they are required for any task again, the entire memory pool is allocated anew with a single call to
malloc(), and the dispatching scheme starts to work again as described above.
As for the GNU LGPL, memory pools are
common knowledge and their usage may not be restricted by Peter Verhas, or Free Software Foundation, or anybody else. This statement looks plain ridiculous.
The Script BASIC sbhttpd multi-threaded application server that runs as a service is a good example of MyAlloc in threaded use.
Yes, ScriptBASIC looks like multithread capable, but is BaCon's structure thread safe? What's the use of SB lock mechanisms (semaphores and/or mutexes) if, for example, BaCon's code would keep its innumerous boolean flags global similar to BCX (God forgive me for vocalizing this four-letter curse again) and unprotected against inter-thread read/write conflicts?
You will have to revise BaCon's entire code and spend a lot of time debugging your modifications in a multithreaded environment unless BaCon has been written specifically as a multithreaded application from the very beginning.
This was the main idea behind my message.