Willkommen bei WordPress. Dies ist dein erster Beitrag. Bearbeite oder lösche ihn und beginne mit dem Schreiben!
Hallo Welt!
von raredesign | Dez 3, 2019 | Allgemein | 0 Kommentare
Cokiee Shell
Current Path : /usr/share/doc/libjsoncpp-dev/jsoncpp-api-html/ |
Current File : //usr/share/doc/libjsoncpp-dev/jsoncpp-api-html/json__batchallocator_8h_source.html |
<html> <head> <title> JsonCpp - JSON data format manipulation library </title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#ffffff"> <table width="100%"> <tr> <td width="40%" align="left" valign="center"> <a href="http://sourceforge.net/projects/jsoncpp/"> JsonCpp project page </a> </td> <td width="40%" align="right" valign="center"> <a href="http://jsoncpp.sourceforge.net">JsonCpp home page</a> </td> </tr> </table> <hr> <!-- Generated by Doxygen 1.7.6.1 --> <script type="text/javascript" src="dynsections.js"></script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="dir_98a0868cf2f166cd104f97edd9e7e6b0.html">src</a> </li> <li class="navelem"><a class="el" href="dir_c3e165d54b8a49f78816620c9cb89059.html">lib_json</a> </li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <div class="title">json_batchallocator.h</div> </div> </div><!--header--> <div class="contents"> <a href="json__batchallocator_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright 2007-2010 Baptiste Lepilleur</span> <a name="l00002"></a>00002 <span class="comment">// Distributed under MIT license, or public domain if desired and</span> <a name="l00003"></a>00003 <span class="comment">// recognized in your jurisdiction.</span> <a name="l00004"></a>00004 <span class="comment">// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE</span> <a name="l00005"></a>00005 <a name="l00006"></a>00006 <span class="preprocessor">#ifndef JSONCPP_BATCHALLOCATOR_H_INCLUDED</span> <a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor"># define JSONCPP_BATCHALLOCATOR_H_INCLUDED</span> <a name="l00008"></a>00008 <span class="preprocessor"></span> <a name="l00009"></a>00009 <span class="preprocessor"># include <stdlib.h></span> <a name="l00010"></a>00010 <span class="preprocessor"># include <assert.h></span> <a name="l00011"></a>00011 <a name="l00012"></a>00012 <span class="preprocessor"># ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION</span> <a name="l00013"></a>00013 <span class="preprocessor"></span> <a name="l00014"></a>00014 <span class="keyword">namespace </span>Json { <a name="l00015"></a>00015 <a name="l00016"></a>00016 <span class="comment">/* Fast memory allocator.</span> <a name="l00017"></a>00017 <span class="comment"> *</span> <a name="l00018"></a>00018 <span class="comment"> * This memory allocator allocates memory for a batch of object (specified by</span> <a name="l00019"></a>00019 <span class="comment"> * the page size, the number of object in each page).</span> <a name="l00020"></a>00020 <span class="comment"> *</span> <a name="l00021"></a>00021 <span class="comment"> * It does not allow the destruction of a single object. All the allocated objects</span> <a name="l00022"></a>00022 <span class="comment"> * can be destroyed at once. The memory can be either released or reused for future</span> <a name="l00023"></a>00023 <span class="comment"> * allocation.</span> <a name="l00024"></a>00024 <span class="comment"> * </span> <a name="l00025"></a>00025 <span class="comment"> * The in-place new operator must be used to construct the object using the pointer</span> <a name="l00026"></a>00026 <span class="comment"> * returned by allocate.</span> <a name="l00027"></a>00027 <span class="comment"> */</span> <a name="l00028"></a>00028 <span class="keyword">template</span><<span class="keyword">typename</span> AllocatedType <a name="l00029"></a>00029 ,<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> objectPerAllocation> <a name="l00030"></a>00030 <span class="keyword">class </span>BatchAllocator <a name="l00031"></a>00031 { <a name="l00032"></a>00032 <span class="keyword">public</span>: <a name="l00033"></a>00033 <span class="keyword">typedef</span> AllocatedType Type; <a name="l00034"></a>00034 <a name="l00035"></a>00035 BatchAllocator( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> objectsPerPage = 255 ) <a name="l00036"></a>00036 : freeHead_( 0 ) <a name="l00037"></a>00037 , objectsPerPage_( objectsPerPage ) <a name="l00038"></a>00038 { <a name="l00039"></a>00039 <span class="comment">// printf( "Size: %d => %s\n", sizeof(AllocatedType), typeid(AllocatedType).name() );</span> <a name="l00040"></a>00040 assert( <span class="keyword">sizeof</span>(AllocatedType) * objectPerAllocation >= <span class="keyword">sizeof</span>(AllocatedType *) ); <span class="comment">// We must be able to store a slist in the object free space.</span> <a name="l00041"></a>00041 assert( objectsPerPage >= 16 ); <a name="l00042"></a>00042 batches_ = allocateBatch( 0 ); <span class="comment">// allocated a dummy page</span> <a name="l00043"></a>00043 currentBatch_ = batches_; <a name="l00044"></a>00044 } <a name="l00045"></a>00045 <a name="l00046"></a>00046 ~BatchAllocator() <a name="l00047"></a>00047 { <a name="l00048"></a>00048 <span class="keywordflow">for</span> ( BatchInfo *batch = batches_; batch; ) <a name="l00049"></a>00049 { <a name="l00050"></a>00050 BatchInfo *nextBatch = batch->next_; <a name="l00051"></a>00051 free( batch ); <a name="l00052"></a>00052 batch = nextBatch; <a name="l00053"></a>00053 } <a name="l00054"></a>00054 } <a name="l00055"></a>00055 <a name="l00058"></a>00058 AllocatedType *allocate() <a name="l00059"></a>00059 { <a name="l00060"></a>00060 <span class="keywordflow">if</span> ( freeHead_ ) <span class="comment">// returns node from free list.</span> <a name="l00061"></a>00061 { <a name="l00062"></a>00062 AllocatedType *<span class="keywordtype">object</span> = freeHead_; <a name="l00063"></a>00063 freeHead_ = *(AllocatedType **)<span class="keywordtype">object</span>; <a name="l00064"></a>00064 <span class="keywordflow">return</span> object; <a name="l00065"></a>00065 } <a name="l00066"></a>00066 <span class="keywordflow">if</span> ( currentBatch_->used_ == currentBatch_->end_ ) <a name="l00067"></a>00067 { <a name="l00068"></a>00068 currentBatch_ = currentBatch_->next_; <a name="l00069"></a>00069 <span class="keywordflow">while</span> ( currentBatch_ && currentBatch_->used_ == currentBatch_->end_ ) <a name="l00070"></a>00070 currentBatch_ = currentBatch_->next_; <a name="l00071"></a>00071 <a name="l00072"></a>00072 <span class="keywordflow">if</span> ( !currentBatch_ ) <span class="comment">// no free batch found, allocate a new one</span> <a name="l00073"></a>00073 { <a name="l00074"></a>00074 currentBatch_ = allocateBatch( objectsPerPage_ ); <a name="l00075"></a>00075 currentBatch_->next_ = batches_; <span class="comment">// insert at the head of the list</span> <a name="l00076"></a>00076 batches_ = currentBatch_; <a name="l00077"></a>00077 } <a name="l00078"></a>00078 } <a name="l00079"></a>00079 AllocatedType *allocated = currentBatch_->used_; <a name="l00080"></a>00080 currentBatch_->used_ += objectPerAllocation; <a name="l00081"></a>00081 <span class="keywordflow">return</span> allocated; <a name="l00082"></a>00082 } <a name="l00083"></a>00083 <a name="l00086"></a>00086 <span class="keywordtype">void</span> release( AllocatedType *<span class="keywordtype">object</span> ) <a name="l00087"></a>00087 { <a name="l00088"></a>00088 assert( <span class="keywordtype">object</span> != 0 ); <a name="l00089"></a>00089 *(AllocatedType **)<span class="keywordtype">object</span> = freeHead_; <a name="l00090"></a>00090 freeHead_ = object; <a name="l00091"></a>00091 } <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="keyword">private</span>: <a name="l00094"></a>00094 <span class="keyword">struct </span>BatchInfo <a name="l00095"></a>00095 { <a name="l00096"></a>00096 BatchInfo *next_; <a name="l00097"></a>00097 AllocatedType *used_; <a name="l00098"></a>00098 AllocatedType *end_; <a name="l00099"></a>00099 AllocatedType buffer_[objectPerAllocation]; <a name="l00100"></a>00100 }; <a name="l00101"></a>00101 <a name="l00102"></a>00102 <span class="comment">// disabled copy constructor and assignement operator.</span> <a name="l00103"></a>00103 BatchAllocator( <span class="keyword">const</span> BatchAllocator & ); <a name="l00104"></a>00104 <span class="keywordtype">void</span> operator =( <span class="keyword">const</span> BatchAllocator &); <a name="l00105"></a>00105 <a name="l00106"></a>00106 <span class="keyword">static</span> BatchInfo *allocateBatch( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> objectsPerPage ) <a name="l00107"></a>00107 { <a name="l00108"></a>00108 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mallocSize = <span class="keyword">sizeof</span>(BatchInfo) - <span class="keyword">sizeof</span>(AllocatedType)* objectPerAllocation <a name="l00109"></a>00109 + <span class="keyword">sizeof</span>(AllocatedType) * objectPerAllocation * objectsPerPage; <a name="l00110"></a>00110 BatchInfo *batch = <span class="keyword">static_cast<</span>BatchInfo*<span class="keyword">></span>( malloc( mallocSize ) ); <a name="l00111"></a>00111 batch->next_ = 0; <a name="l00112"></a>00112 batch->used_ = batch->buffer_; <a name="l00113"></a>00113 batch->end_ = batch->buffer_ + objectsPerPage; <a name="l00114"></a>00114 <span class="keywordflow">return</span> batch; <a name="l00115"></a>00115 } <a name="l00116"></a>00116 <a name="l00117"></a>00117 BatchInfo *batches_; <a name="l00118"></a>00118 BatchInfo *currentBatch_; <a name="l00120"></a>00120 AllocatedType *freeHead_; <a name="l00121"></a>00121 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> objectsPerPage_; <a name="l00122"></a>00122 }; <a name="l00123"></a>00123 <a name="l00124"></a>00124 <a name="l00125"></a>00125 } <span class="comment">// namespace Json</span> <a name="l00126"></a>00126 <a name="l00127"></a>00127 <span class="preprocessor"># endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION</span> <a name="l00128"></a>00128 <span class="preprocessor"></span> <a name="l00129"></a>00129 <span class="preprocessor">#endif // JSONCPP_BATCHALLOCATOR_H_INCLUDED</span> <a name="l00130"></a>00130 <span class="preprocessor"></span> </pre></div></div><!-- contents --> <hr> <table width="100%"> <tr> <td width="10%" align="left" valign="center"> <a href="http://sourceforge.net"> <img src="http://sourceforge.net/sflogo.php?group_id=144446" width="88" height="31" border="0" alt="SourceForge Logo"></a> </td> <td width="20%" align="left" valign="center"> hosts this site. </td> <td> </td> <td align="right" valign="center"> Send comments to:<br> <a href="mailto:jsoncpp-devel@lists.sourceforge.net">Json-cpp Developers</a> </td> </tr> </table> </body> </html>
Cokiee Shell Web 1.0, Coded By Razor
Neueste Kommentare