SynopsisInitialize the GoAhead block memory allocator. Prototypes#include "webs.h" int bopen(char *buf, int bufsize, int flags); Parameters
DescriptionThe bopen procedure initializes the GoAhead block memory allocator. The block allocator is a very efficient memory allocator that uses binary queues to store blocks of memory. It does not do block coalescing, nor does it attempt to eliminate fragmentation. Once released by bfree, memory is not actually freed to the operating system, but is kept on the relevant binary queue for future use by the application. The goal of the block allocator is to provide guaranteed, rapid allocation. By calling bopen with the application memory requirements, memory can be defined or allocated upfront and subsequent calls to balloc are more likely to succeed. The block allocator is not perfect; you can still get free memory of one class queue while memory requests for a large size cannot be satisfied. However, in practice, many embedded applications tend to allocate memory in a pattern and the balloc memory allocator works well in such environments. The memory usage of the GoAhead WebServer has been optimized to allocate from the fixed pool defined by bopen and it should be very predictable in its requirements. The bstats procedure may be used to print out current memory statistics, including per file usage information. If you wish to supply a static buffer for the block allocator to use, set the buf argument to a buffer of your choice and set bufsize to specify the size of the buffer. You must also set flags to be B_USER_BUF. The block allocated can also use the operating system's malloc call to get memory if the flags argument is set to B_USE_MALLOC. Return ValueReturns 0 on success. Returns -1 if memory cannot be provided. Exampleif (bopen(NULL, B_DEFAULT_MEM, 0) < 0) { return NULL; } Stability ClassificationStable. See Also |