haiku-website/static/legacy-docs/bebook/BMallocIO.html

84 lines
15 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - Classes And Methods - The Support Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheSupportKit.html" title="The Support Kit" /><link rel="prev" href="BLocker.html" title="BLocker" /><link rel="next" href="BMemoryIO.html" title="BMemoryIO" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="BLocker.html" title="BLocker"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheSupportKit.html" title="The Support Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="BMemoryIO.html" title="BMemoryIO"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - Classes And Methods - The Support Kit</div></div><div id="headerB">Prev: <a href="BLocker.html">BLocker</a>  Up: <a href="TheSupportKit.html">The Support Kit</a>  Next: <a href="BMemoryIO.html">BMemoryIO</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO"></a>BMallocIO</h2></div></div></div><a id="id1272134" class="indexterm"></a><div class="classheader"><table border="0"><colgroup><col /><col /></colgroup><tbody><tr><td><table width="100%" border="0"><colgroup><col /><col /></colgroup><tbody><tr><td>Derived From:</td><td>
<a class="link" href="BPositionIO.html" title="BPositionIO"><code class="classname">BPositionIO</code></a>
</td></tr><tr><td>Mix-in Classes:</td><td></td></tr><tr><td>Declared In:</td><td><code class="filename">support/DataIO.h</code></td></tr><tr><td>Library:</td><td><code class="filename">libbe.so</code></td></tr><tr><td>Allocation:</td><td></td></tr></tbody></table></td><td>
<a class="link overview" href="BMallocIO_Overview.html" title="BMallocIO">Class Overview</a>
<div class="toc"><ul><li><span class="section"><a href="BMallocIO.html#BMallocIO_ConstructorDestructor">Constructor and Destructor</a></span></li><li><span class="section"><a href="BMallocIO.html#BMallocIO_MemberFunctions">Member Functions</a></span></li></ul></div>
</td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_ConstructorDestructor"></a>Constructor and Destructor</h3></div></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_Constructor"></a>BMallocIO</h4></div></div></div><code class="constructorsynopsis cpp"><span class="methodname">BMallocIO</span>();</code><p>
The <code class="classname">BMallocIO</code> constructor creates an empty object and sets the default
block size to 256 bytes. The constructor doesn't allocate any memory;
memory is allocated when you first write to the object or when you call
<a class="link" href="BMallocIO.html#BMallocIO_SetSize"><code class="methodname">SetSize()</code></a> to set the amount of memory.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_Destructor"></a>~BMallocIO()</h4></div></div></div><code class="destructorsynopsis cpp"><span class="modifier">virtual </span><span class="methodname">~BMallocIO</span>();</code><p>
The <code class="classname">BMallocIO</code> destructor frees all memory that was allocated by the
object.
</p></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_MemberFunctions"></a>Member Functions</h3></div></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_Buffer"></a><a id="BMallocIO_BufferLength"></a>
Buffer(), BufferLength()</h4></div></div></div><code class="methodsynopsis cpp"><span class="modifier">const </span><span class="type">void* </span><span class="methodname">Buffer</span>() <span class="modifier">const</span>;</code><code class="methodsynopsis cpp"><span class="type">size_t </span><span class="methodname">BufferLength</span>() <span class="modifier">const</span>;</code><p>
<code class="methodname">Buffer()</code> returns a pointer to the memory that the
<code class="classname">BMallocIO</code> object has allocated, or
<code class="constant">NULL</code> if it hasn't yet had occasion to allocate any memory.
</p><p>
<code class="methodname">BufferLength()</code> returns the number of data bytes
in the buffer (not necessarily the full number of bytes that were allocated).
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_ReadAt"></a>ReadAt()</h4></div></div></div><code class="methodsynopsis cpp"><span class="modifier">virtual </span><span class="type">ssize_t </span><span class="methodname">ReadAt</span>(<span class="methodparam"><span class="type">off_t </span><span class="parameter">position</span></span>,<br />                       <span class="methodparam"><span class="type">void* </span><span class="parameter">buffer</span></span>,<br />                       <span class="methodparam"><span class="type">size_t </span><span class="parameter">numBytes</span></span>);</code><p>
Reads up to <code class="parameter">numBytes</code> bytes of data from the object and copies it into the
<code class="parameter">buffer</code>. Returns the actual number of bytes placed in the buffer. The data
is read beginning at the <code class="parameter">position</code> offset.
</p><p>
This function doesn't read beyond the end of the data. If there are fewer
than <code class="parameter">numBytes</code> of data available at the <code class="parameter">position</code>
offset, it reads only
through the last data byte and returns a smaller number than <code class="parameter">numBytes</code>. If
<code class="parameter">position</code> is out of range, it returns 0.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_Seek"></a><a id="BMallocIO_Position"></a>
Seek(), Position()</h4></div></div></div><code class="methodsynopsis cpp"><span class="modifier">virtual </span><span class="type">off_t </span><span class="methodname">Seek</span>(<span class="methodparam"><span class="type">off_t </span><span class="parameter">position</span></span>,<br />                   <span class="methodparam"><span class="type">int32 </span><span class="parameter">mode</span></span>);</code><code class="methodsynopsis cpp"><span class="modifier">virtual </span><span class="type">off_t </span><span class="methodname">Position</span>() <span class="modifier">const</span>;</code><p>
<code class="methodname">Seek()</code> sets the position in the data buffer where the
<a class="link" href="BPositionIO.html#BPositionIO_Read" title="Read(), ReadAt()"><code class="methodname">Read()</code></a> and
<a class="link" href="BPositionIO.html#BPositionIO_Write" title="Write(), WriteAt()"><code class="methodname">Write()</code></a>
functions (inherited from
<a class="link" href="BPositionIO.html" title="BPositionIO"><code class="classname">BPositionIO</code></a>) begin reading and writing. How the
<code class="parameter">position</code> argument is understood depends on the <code class="parameter">mode</code>
flag. There are three possible modes:
</p><table class="variablelist constants"><thead><tr><th>Constant</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">SEEK_SET</code>.</span></p></td><td><p>The <code class="parameter">position</code> passed is an offset from the beginning of
allocated memory; in other words, the current position is set to
<code class="parameter">position</code>. For this mode, <code class="parameter">position</code> should be a positive value.</p></td></tr><tr><td><p><span class="term"><code class="constant">SEEK_CUR</code>.</span></p></td><td><p>The <code class="parameter">position</code> argument is an offset from the current
position; the value of the argument is added to the current position.</p></td></tr><tr><td><p><span class="term"><code class="constant">SEEK_END</code>.</span></p></td><td><p>The <code class="parameter">position</code> argument is an offset from the end of the
object's data (not necessarily from the end of allocated memory).
Positive values seek beyond the end of the data; negative values seek
backwards into the data.</p></td></tr></tbody></table><p>
Attempts to seek beyond the end of allocated memory are legal: When
<a class="link" href="BDataIO.html#BDataIO_Write" title="Write()"><code class="methodname">Write()</code></a>
is subsequently called, the object updates its conception of
where the data ends to bring the current position within range. If
necessary, enough memory will be allocated to accommodate any data added
at the current position.
</p><p>
Both <code class="methodname">Seek()</code> and <code class="methodname">Position()</code>
return the current position as an offset in
bytes from the beginning of allocated memory.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_SetBlockSize"></a><a id="BMallocIO_SetSize"></a>
SetBlockSize(), SetSize()</h4></div></div></div><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">SetBlockSize</span>(<span class="methodparam"><span class="type">size_t </span><span class="parameter">blockSize</span></span>);</code><code class="methodsynopsis cpp"><span class="modifier">virtual </span><span class="type">status_t </span><span class="methodname">SetSize</span>(<span class="methodparam"><span class="type">off_t </span><span class="parameter">numBytes</span></span>);</code><p>
<code class="methodname">SetBlockSize()</code> sets the size of the memory blocks that the
<code class="classname">BMallocIO</code>
object deals with. The object allocates memory in multiples of the block
size. The default is 256 bytes.
</p><p>
<code class="methodname">SetSize()</code> sets the size of allocated memory to
<code class="parameter">numBytes</code> (modulo the block
size). Shrinking the buffer should always be successful (<code class="constant">B_OK</code>); if the
buffer can't be grown, <code class="constant">B_NO_MEMORY</code> is returned.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BMallocIO_WriteAt"></a>WriteAt()</h4></div></div></div><code class="methodsynopsis cpp"><span class="modifier">virtual </span><span class="type">ssize_t </span><span class="methodname">WriteAt</span>(<span class="methodparam"><span class="type">off_t </span><span class="parameter">position</span></span>,<br />                        <span class="methodparam"><span class="modifier">const </span><span class="type">void* </span><span class="parameter">buffer</span></span>,<br />                        <span class="methodparam"><span class="type">size_t </span><span class="parameter">numBytes</span></span>);</code><p>
Copies <code class="parameter">numBytes</code> bytes of data from <code class="parameter">buffer</code> into the object's data
beginning at <code class="parameter">position</code>.
</p><p>
A successful <code class="methodname">WriteAt()</code> always returns <code class="parameter">numBytes</code> -
<code class="methodname">WriteAt()</code>
reallocates the buffer (in multiples of the block size) if it needs more
room. If the reallocation fails, this function returns <code class="constant">B_NO_MEMORY</code>.
</p></div></div></div><div id="footer"><hr /><div id="footerT">Prev: <a href="BLocker.html">BLocker</a>  Up: <a href="TheSupportKit.html">The Support Kit</a>  Next: <a href="BMemoryIO.html">BMemoryIO</a> </div><div id="footerB"><div id="footerBL"><a href="BLocker.html" title="BLocker"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheSupportKit.html" title="The Support Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="BMemoryIO.html" title="BMemoryIO"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>