📄 bopen.htm
字号:
<html>
<head>
<title>bopen - basic</title>
<link rel="stylesheet" href="../../../style/doc.htm" type="text/css">
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="title-left"><b>bopen</b></td>
<td class="title-center"><b>basic</b></td>
<td class="title-right"><b>EMF</b></td>
</tr>
</table>
<hr>
<h2>Synopsis</h2>
<p>Initialize the GoAhead Block Memory Allocator.</p>
<h2>Prototypes</h2>
<pre>
int <b>bopen</b>(char *buf, int bufsize, int flags);
</pre>
<h2>Parameters</h2>
<p>
<table width="90%">
<tr>
<td width="40">buf </td>
<td>Pointer to buffer to use for initial memory allocation </td>
</tr>
<tr>
<td width="40">bufsize </td>
<td>Size of buf </td>
</tr>
<tr>
<td width="40">flags </td>
<td>Open mode flags</td>
</tr>
</table>
</p>
<h2>Description</h2>
<p>The bopen procedure initializes the GoAhead Block Memory Allocator.
The block allocator is a very efficient memory allocated 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.</p>
<p> </p>
<p>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 up-front and subsequent calls to
<a href="balloc.htm">balloc</a> are more likely to succeed. The block
allocator is not perfect, you can still get free memory of on 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
include per file usage information.</p>
<p> </p>
<p>If you wish to supply a static buffer for the block allocator to use, set
the <em>buf </em>argument to a buffer of your choice and set <em>bufsize </em>
specifies the size of the buffer. You must also set <em>flags </em>to be
B_USER_BUF. The block allocated can also use the operating systems's
<em>malloc </em>call to get memory if the <em>flags</em> argument is set to
B_USE_MALLOC.</p>
<h2>Return Value</h2>
<p>Pointer to the allocated buffer. If memory cannot be provided, NULL is
returned.</p>
<h2>Example</h2>
<pre>
char buf[20 * 1024];
bopen(buf, sizeof(buf));
</pre>
<h2>See Also</h2>
<p><a href="balloc.htm">balloc</a>, <a href="bfree.htm">bfree</a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -