|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52546 - in sandbox/memory: boost/memory boost/memory/container libs/memory/examples/pool
From: xushiweizh_at_[hidden]
Date: 2009-04-22 13:21:11
Author: xushiwei
Date: 2009-04-22 13:21:09 EDT (Wed, 22 Apr 2009)
New Revision: 52546
URL: http://svn.boost.org/trac/boost/changeset/52546
Log:
example: pool
Added:
sandbox/memory/libs/memory/examples/pool/
sandbox/memory/libs/memory/examples/pool/simple_examples.cpp (contents, props changed)
sandbox/memory/libs/memory/examples/pool/vc9-win32.vcproj (contents, props changed)
Text files modified:
sandbox/memory/boost/memory/container/dcl_list.hpp | 1 -
sandbox/memory/boost/memory/fixed_alloc.hpp | 22 +++++++++++++++-------
2 files changed, 15 insertions(+), 8 deletions(-)
Modified: sandbox/memory/boost/memory/container/dcl_list.hpp
==============================================================================
--- sandbox/memory/boost/memory/container/dcl_list.hpp (original)
+++ sandbox/memory/boost/memory/container/dcl_list.hpp 2009-04-22 13:21:09 EDT (Wed, 22 Apr 2009)
@@ -74,7 +74,6 @@
public:
bool BOOST_MEMORY_CALL empty() const
{
- BOOST_MEMORY_ASSERT(m_next == this || m_next != m_prev);
return m_next == this;
}
Modified: sandbox/memory/boost/memory/fixed_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/fixed_alloc.hpp (original)
+++ sandbox/memory/boost/memory/fixed_alloc.hpp 2009-04-22 13:21:09 EDT (Wed, 22 Apr 2009)
@@ -25,8 +25,13 @@
// -------------------------------------------------------------------------
// class fixed_alloc
-#ifndef BOOST_MEMORY_ROUND
-#define BOOST_MEMORY_ROUND(x, y) (((x)+((y)-1)) & ~((y)-1))
+#ifndef ROUND
+#define ROUND(x, y) (((x)+((y)-1)) & ~((y)-1))
+#endif
+
+#ifndef MAX
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
template <class PolicyT>
@@ -62,11 +67,13 @@
MemBlock* pBlock;
};
- enum { ChunkHeaderSize = sizeof(ChunkHeader) };
-
struct FreeChunk : public dcl_list_node<FreeChunk>
{
};
+
+ enum { ChunkHeaderSize = sizeof(ChunkHeader) };
+ enum { MinElemBytes = sizeof(FreeChunk) };
+
#pragma pack()
AllocT m_alloc;
@@ -78,10 +85,11 @@
private:
void init_(size_type cbElem)
{
- m_cbChunk = BOOST_MEMORY_ROUND(cbElem, ChunkHeaderSize) + ChunkHeaderSize;
+ cbElem = ROUND(cbElem, sizeof(void*));
+ m_cbChunk = MAX(cbElem, MinElemBytes) + ChunkHeaderSize;
m_nMaxPerBlock = BlockSize / m_cbChunk;
- BOOST_MEMORY_ASSERT(cbElem > 0 && m_nMaxPerBlock > 0);
+ BOOST_MEMORY_ASSERT(m_nMaxPerBlock > 0);
}
public:
@@ -150,7 +158,7 @@
for (MemBlock* blk = m_blks.first(); !m_blks.done(blk); blk = nextBlk)
{
nextBlk = blk->next();
- m_alloc.deallocate(blk)
+ m_alloc.deallocate(blk);
}
m_blks.clear();
m_freelist.clear();
Added: sandbox/memory/libs/memory/examples/pool/simple_examples.cpp
==============================================================================
--- (empty file)
+++ sandbox/memory/libs/memory/examples/pool/simple_examples.cpp 2009-04-22 13:21:09 EDT (Wed, 22 Apr 2009)
@@ -0,0 +1,52 @@
+//
+// simple_examples.cpp
+//
+// Copyright (c) 2004 - 2008 xushiwei (xushiweizh_at_[hidden])
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/memory/index.htm for documentation.
+//
+#include <boost/memory.hpp>
+
+// -------------------------------------------------------------------------
+
+#ifndef countof
+#define countof(array) (sizeof(array)/sizeof(array[0]))
+#endif
+
+void testPool()
+{
+ int i;
+ boost::memory::pool alloc(sizeof(int));
+
+ void* p[3000];
+ for (i = 0; i < countof(p); ++i)
+ p[i] = alloc.allocate();
+ for (i = 0; i < countof(p); ++i)
+ alloc.deallocate(p[i]);
+
+ void* p1 = alloc.allocate();
+ void* p2 = alloc.allocate();
+ void* p3 = alloc.allocate();
+
+ alloc.deallocate(p2);
+ alloc.deallocate(p1);
+ alloc.deallocate(p3);
+
+ //
+ // Note: It's ok even if you forget to free allocated memory!
+ //
+ for (i = 0; i < 1000; ++i)
+ alloc.allocate();
+}
+
+int main()
+{
+ NS_BOOST_MEMORY::enableMemoryLeakCheck();
+
+ testPool();
+ return 0;
+}
Added: sandbox/memory/libs/memory/examples/pool/vc9-win32.vcproj
==============================================================================
--- (empty file)
+++ sandbox/memory/libs/memory/examples/pool/vc9-win32.vcproj 2009-04-22 13:21:09 EDT (Wed, 22 Apr 2009)
@@ -0,0 +1,204 @@
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="simplest"
+ ProjectGUID="{EE4C99E9-EC3C-D26F-EE7F-A387A0E0425E}"
+ TargetFrameworkVersion="0"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName="Release/prj2json.tlb"
+ HeaderFileName=""
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ AdditionalIncludeDirectories="../../../.."
+ PreprocessorDefinitions="WIN32;__32BIT__;_CONSOLE;NDEBUG;_MT"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ PrecompiledHeaderFile=""
+ AssemblerListingLocation="Release/"
+ ObjectFile="Release/"
+ ProgramDataBaseFileName="Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="WIN32;__32BIT__;_CONSOLE;NDEBUG;_MT"
+ Culture="2052"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="Release/simplest.exe"
+ LinkIncremental="1"
+ SuppressStartupBanner="true"
+ AdditionalLibraryDirectories="../../lib"
+ GenerateDebugInformation="false"
+ ProgramDatabaseFile="Release/simplest.pdb"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName="Debug/prj2json.tlb"
+ HeaderFileName=""
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ InlineFunctionExpansion="0"
+ AdditionalIncludeDirectories="../../../.."
+ PreprocessorDefinitions="WIN32;__32BIT__;_CONSOLE;_DEBUG;_MT"
+ StringPooling="true"
+ RuntimeLibrary="3"
+ EnableFunctionLevelLinking="true"
+ PrecompiledHeaderFile=""
+ AssemblerListingLocation="Debug/"
+ ObjectFile="Debug/"
+ ProgramDataBaseFileName="Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="WIN32;__32BIT__;_CONSOLE;_DEBUG;_MT"
+ Culture="2052"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="Debug/simplest.exe"
+ LinkIncremental="1"
+ SuppressStartupBanner="true"
+ AdditionalLibraryDirectories="../../lib"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="Debug/simplest.pdb"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath="simple_examples.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk