1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/memorypool.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2002 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>
<font color="#a020f0">#ifndef RUDIMENTS_MEMORYPOOL_H</font>
<font color="#a020f0">#define RUDIMENTS_MEMORYPOOL_H</font>
<font color="#a020f0">#include </font><font color="#ff00ff"><rudiments/private/memorypoolincludes.h></font>
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>
<font color="#0000ff">// The memorypool class provides methods for creating and using a memory pool.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// If you have an iterative process that requires variable amounts of ram</font>
<font color="#0000ff">// for each iteration, using a memory pool can be faster than allocating</font>
<font color="#0000ff">// and deallocating memory on-demand and less resource-intensive than</font>
<font color="#0000ff">// allocating static buffers that are large enough to accommodate the maximum</font>
<font color="#0000ff">// amount of data you may have to store.</font>
<font color="#2e8b57"><b>class</b></font> memorypoolprivate;
<font color="#2e8b57"><b>class</b></font> memorypool {
<font color="#a52a2a"><b>public</b></font>:
memorypool(<font color="#2e8b57"><b>size_t</b></font> initialsize,
<font color="#2e8b57"><b>size_t</b></font> increment,
<font color="#2e8b57"><b>size_t</b></font> resizeinterval);
<font color="#0000ff">// Creates a memory pool of initial size "initialsize".</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// When the pool needs to grow, it will grow by at least</font>
<font color="#0000ff">// "increment" bytes. If more than increment bytes</font>
<font color="#0000ff">// are requested, it will grow by that amount instead.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// When free() has been called "resizeinterval" times,</font>
<font color="#0000ff">// it will evaluate the average amount of memory</font>
<font color="#0000ff">// malloc'ed (since the last time it did this) and</font>
<font color="#0000ff">// resize the initial buffer size to this size. This</font>
<font color="#0000ff">// will ideally minimize the </font>
~memorypool();
<font color="#0000ff">// Destroys the memory pool.</font>
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *malloc(<font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Returns a pointer to a contiguous block of "size"</font>
<font color="#0000ff">// bytes in the pool. The pool will grow as necessary</font>
<font color="#0000ff">// to accomodate allocations.</font>
<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *calloc(<font color="#2e8b57"><b>size_t</b></font> size);
<font color="#0000ff">// Returns a pointer to a contiguous block of "size"</font>
<font color="#0000ff">// bytes in the pool. The pool will grow as necessary</font>
<font color="#0000ff">// to accomodate allocations. Each byte of data in</font>
<font color="#0000ff">// the block of data is set to NULL.</font>
<font color="#2e8b57"><b>void</b></font> free();
<font color="#0000ff">// Shrinks the pool back down to it's initial size</font>
<font color="#0000ff">// and frees all previously allocated blocks.</font>
<font color="#2e8b57"><b>void</b></font> print();
<font color="#0000ff">// Prints a visual representation of the pool.</font>
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/memorypool.h></font>
};
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>
<font color="#a020f0">#endif</font>
</pre>
</body>
</html>
|