Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 2e9c43658e374d290a2de15d25134ac8 > files > 707

db4o-doc-8.0-1.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Configuration|File Configuration|Storage" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Memory Storage	</title>
        <script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
	var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
	ZeroClipboard.setMoviePath(pathToFlash);
			
	function bindToClipBord(element,content){
		var clip = new ZeroClipboard.Client();
		clip.setText(content);
		clip.glue(element);
	};
		
	if(location.protocol==='file:'){
		$('.copylink-marker').remove();
	} else{
			$('.copylink-marker').each(function(){
				var text = $(this).parent().parent().children('.prettyprint').html();
				$(this).hover(function(){
					bindToClipBord(this,text);
				},
				function(){});
			});	
	}		
	prettyPrint();	
};
                /* ]]> */</script>
        <link href="../../../SkinSupport/MadCap.css" rel="stylesheet" />
        <link href="../../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
        <script src="../../../SkinSupport/MadCapAll.js">
        </script>
        <script src="../../../Resources/Code/prettify.js">
        </script>
        <script src="../../../Resources/Code/lang-vb.js">
        </script>
        <script src="../../../Resources/Code/jquery.min.js">
        </script>
        <script src="../../../Resources/Code/ZeroClipboard.js">
        </script>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../../index_CSH.html#configuration/file/storage/memory_storage.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../../configuration.htm">Configuration</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../../file_configuration.htm">File Configuration</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../storage.htm">Storage</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Memory Storage	</span>
        </div>
        <p>
            <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
				document.write("Direct Link");
			document.write('</a>');/*]]>*/</script>
        </p>
        <p>
        </p>
        <h1><a name="kanchor47"></a>Memory Storage</h1>
        <p>The MemoryStorage allows you to create
and use a db4o database fully in RAM. This strategy eliminates long disk access
times and makes db4o much faster.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
MemoryStorage memory = new MemoryStorage();
configuration.File.<span class="MCPopup"><a href="javascript:void(0);" class="MCPopupSpot" onclick="FMCPopup( event, this ); return false;" MadCap:src="../storage.htm">Storage<img style="border: none;margin-left: 5px;" src="../../../SkinSupport/ExpandingClosed.gif" MadCap:altsrc="../../../SkinSupport/ExpandingOpen.gif" class="MCExpandingIcon" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../../SkinSupport/ExpandingOpen.gif' ); }" /></a></span> = memory;
IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o");</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.cs: Using memory-storage
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
Dim memory As New MemoryStorage()
configuration.File.Storage = memory</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.vb: Using memory-storage
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <p>MemoryStorage can be
created without any additional parameters passed to the constructor. In this
case default configuration values will be used. </p>
        <h2>PagingMemoryStorage</h2>
        <p>The regular MemoryStorage implementation keeps all the content in a single byte-array. However this brings some issues. When the database outgrows the array-size, a new, larger array is created and the content is copied over. This can be quite slow. Also can cause this a out of memory exception, because during the copying these two large arrays are present. Also, on some runtimes large objects are treated different by the garbage-collector and are less often collected. </p>
        <p>To avoid all this issues, the PagingMemoryStorage uses multiple, small arrays to keep the database in memory. When the database outgrows the storage, only such a smaller arrays needs to be allocated. The old content stays in the existing arrays. No coping is required. </p>
        <p>However managing these arrays cost some small overhead. But for lots of cases, the PagingMemoryStorage is the better choice.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
PagingMemoryStorage memory = new PagingMemoryStorage();
configuration.File.Storage = memory;
IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o");</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.cs: Using paging memory-storage
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
Dim memory As New PagingMemoryStorage()
configuration.File.Storage = memory
Dim container As IObjectContainer = Db4oEmbedded.OpenFile(configuration, "database.db4o")
</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.vb: Using paging memory-storage
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <h2>Growth Strategy for MemoryStorage</h2>
        <p>Growth strategy defines
how the database storage (reserved disk or memory space) will grow when the
current space is not enough anymore.</p>
        <p>DoublingGrowthStrategy - default
setting. When the size of the database is not enough, the reserved size will be
doubled.</p>
        <p>ConstantGrowthStrategy -
a configured amount of bytes will be added to the existing size when necessary.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IGrowthStrategy growStrategy = new ConstantGrowthStrategy(100);
MemoryStorage memory = new MemoryStorage(growStrategy);
configuration.File.Storage = memory;</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.cs: Using memory-storage with constant grow strategy
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim growStrategy As IGrowthStrategy = New ConstantGrowthStrategy(100)
Dim memory As New MemoryStorage(growStrategy)
configuration.File.Storage = memory</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.vb: Using memory-storage with constant grow strategy
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <h2>MemoryBin</h2>
        <p>Each memory storage can contain a collection of memory bins, which are
actually just names memory storages. You can reuse the MemoryBin created
earlier for this MemoryStorage. MemoryBins are identified
by their URI, i.e. when an object container is opened with:</p>
        <p MadCap:conditions="Global.Primary:java" />
        <p MadCap:conditions="Primary..NET">
            <p>.NET:  </p>
            <p><code>Db4oEmbedded.OpenFile(embeddedConfiguration,
"myEmbeddedDb.db4o");</code>
            </p>
        </p>
        <p MadCap:conditions="Global.Primary:net" />
        <p>A MemoryBin with URI = "myEmbeddedDb.db4o"
will be used. If this memory bin does not exist in the storage when the
container is opened, a new MemoryBin will be created and associated with this
URI. When you pass the same memory storage to multiple object containers these containers can access to the same in memory file when they are using the same name.</p>
        <p>More Reading:<ul><li value="1"><p><a href="memory_storage/storing_memorybin_data.htm">Storing MemoryBin Data</a></p></li></ul></p>
        <script type="text/javascript" src="../../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>