removed SmallObjectAllocator

removed SmallObjectAllocator (moved to separate branch) and disabled
default SOO for Any and Dynamic::Var
This commit is contained in:
aleks-f
2013-04-03 20:56:23 -05:00
parent 8c2d5dfed7
commit acbcfc140a
18 changed files with 11 additions and 428 deletions

View File

@@ -6749,10 +6749,6 @@
RelativePath=".\include\Poco\SingletonHolder.h" RelativePath=".\include\Poco\SingletonHolder.h"
> >
</File> </File>
<File
RelativePath=".\include\Poco\SmallObjectAllocator.h"
>
</File>
<File <File
RelativePath=".\include\Poco\SortedDirectoryIterator.h" RelativePath=".\include\Poco\SortedDirectoryIterator.h"
> >

View File

@@ -1040,7 +1040,6 @@
<ClInclude Include="include\Poco\RefCountedObject.h" /> <ClInclude Include="include\Poco\RefCountedObject.h" />
<ClInclude Include="include\Poco\SharedPtr.h" /> <ClInclude Include="include\Poco\SharedPtr.h" />
<ClInclude Include="include\Poco\SingletonHolder.h" /> <ClInclude Include="include\Poco\SingletonHolder.h" />
<ClInclude Include="include\Poco\SmallObjectAllocator.h" />
<ClInclude Include="include\Poco\SortedDirectoryIterator.h" /> <ClInclude Include="include\Poco\SortedDirectoryIterator.h" />
<ClInclude Include="include\Poco\String.h" /> <ClInclude Include="include\Poco\String.h" />
<ClInclude Include="include\Poco\StringTokenizer.h" /> <ClInclude Include="include\Poco\StringTokenizer.h" />

View File

@@ -1859,9 +1859,6 @@
<ClInclude Include="include\Poco\Base32Encoder.h"> <ClInclude Include="include\Poco\Base32Encoder.h">
<Filter>Streams\Header Files</Filter> <Filter>Streams\Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="include\Poco\SmallObjectAllocator.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Poco\Optional.h"> <ClInclude Include="include\Poco\Optional.h">
<Filter>Core\Header Files</Filter> <Filter>Core\Header Files</Filter>
</ClInclude> </ClInclude>

View File

@@ -1044,7 +1044,6 @@
<ClInclude Include="include\Poco\RefCountedObject.h" /> <ClInclude Include="include\Poco\RefCountedObject.h" />
<ClInclude Include="include\Poco\SharedPtr.h" /> <ClInclude Include="include\Poco\SharedPtr.h" />
<ClInclude Include="include\Poco\SingletonHolder.h" /> <ClInclude Include="include\Poco\SingletonHolder.h" />
<ClInclude Include="include\Poco\SmallObjectAllocator.h" />
<ClInclude Include="include\Poco\SortedDirectoryIterator.h" /> <ClInclude Include="include\Poco\SortedDirectoryIterator.h" />
<ClInclude Include="include\Poco\String.h" /> <ClInclude Include="include\Poco\String.h" />
<ClInclude Include="include\Poco\StringTokenizer.h" /> <ClInclude Include="include\Poco\StringTokenizer.h" />

View File

@@ -1049,9 +1049,6 @@
<ClInclude Include="include\Poco\SingletonHolder.h"> <ClInclude Include="include\Poco\SingletonHolder.h">
<Filter>Core\Header Files</Filter> <Filter>Core\Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="include\Poco\SmallObjectAllocator.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Poco\String.h"> <ClInclude Include="include\Poco\String.h">
<Filter>Core\Header Files</Filter> <Filter>Core\Header Files</Filter>
</ClInclude> </ClInclude>

View File

@@ -940,9 +940,6 @@
<File <File
RelativePath=".\include\Poco\SingletonHolder.h"> RelativePath=".\include\Poco\SingletonHolder.h">
</File> </File>
<File
RelativePath=".\include\Poco\SmallObjectAllocator.h">
</File>
<File <File
RelativePath=".\include\Poco\SortedDirectoryIterator.h"> RelativePath=".\include\Poco\SortedDirectoryIterator.h">
</File> </File>

View File

@@ -1255,10 +1255,6 @@
RelativePath=".\include\Poco\SingletonHolder.h" RelativePath=".\include\Poco\SingletonHolder.h"
> >
</File> </File>
<File
RelativePath=".\include\Poco\SmallObjectAllocator.h"
>
</File>
<File <File
RelativePath=".\include\Poco\SortedDirectoryIterator.h" RelativePath=".\include\Poco\SortedDirectoryIterator.h"
> >

View File

@@ -1252,10 +1252,6 @@
RelativePath=".\include\Poco\SingletonHolder.h" RelativePath=".\include\Poco\SingletonHolder.h"
> >
</File> </File>
<File
RelativePath=".\include\Poco\SmallObjectAllocator.h"
>
</File>
<File <File
RelativePath=".\include\Poco\SortedDirectoryIterator.h" RelativePath=".\include\Poco\SortedDirectoryIterator.h"
> >

View File

@@ -1042,7 +1042,6 @@
<ClInclude Include="include\Poco\RefCountedObject.h" /> <ClInclude Include="include\Poco\RefCountedObject.h" />
<ClInclude Include="include\Poco\SharedPtr.h" /> <ClInclude Include="include\Poco\SharedPtr.h" />
<ClInclude Include="include\Poco\SingletonHolder.h" /> <ClInclude Include="include\Poco\SingletonHolder.h" />
<ClInclude Include="include\Poco\SmallObjectAllocator.h" />
<ClInclude Include="include\Poco\SortedDirectoryIterator.h" /> <ClInclude Include="include\Poco\SortedDirectoryIterator.h" />
<ClInclude Include="include\Poco\String.h" /> <ClInclude Include="include\Poco\String.h" />
<ClInclude Include="include\Poco\StringTokenizer.h" /> <ClInclude Include="include\Poco\StringTokenizer.h" />

View File

@@ -1868,9 +1868,6 @@
<ClInclude Include="include\Poco\UTF32Encoding.h"> <ClInclude Include="include\Poco\UTF32Encoding.h">
<Filter>Text\Header Files</Filter> <Filter>Text\Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="include\Poco\SmallObjectAllocator.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="src\pocomsg.rc"> <ResourceCompile Include="src\pocomsg.rc">

View File

@@ -1049,7 +1049,6 @@
<ClInclude Include="include\Poco\RefCountedObject.h" /> <ClInclude Include="include\Poco\RefCountedObject.h" />
<ClInclude Include="include\Poco\SharedPtr.h" /> <ClInclude Include="include\Poco\SharedPtr.h" />
<ClInclude Include="include\Poco\SingletonHolder.h" /> <ClInclude Include="include\Poco\SingletonHolder.h" />
<ClInclude Include="include\Poco\SmallObjectAllocator.h" />
<ClInclude Include="include\Poco\String.h" /> <ClInclude Include="include\Poco\String.h" />
<ClInclude Include="include\Poco\StringTokenizer.h" /> <ClInclude Include="include\Poco\StringTokenizer.h" />
<ClInclude Include="include\Poco\Tuple.h" /> <ClInclude Include="include\Poco\Tuple.h" />

View File

@@ -1052,9 +1052,6 @@
<ClInclude Include="include\Poco\SingletonHolder.h"> <ClInclude Include="include\Poco\SingletonHolder.h">
<Filter>Core\Header Files</Filter> <Filter>Core\Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="include\Poco\SmallObjectAllocator.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Poco\String.h"> <ClInclude Include="include\Poco\String.h">
<Filter>Core\Header Files</Filter> <Filter>Core\Header Files</Filter>
</ClInclude> </ClInclude>

View File

@@ -1250,10 +1250,6 @@
RelativePath=".\include\Poco\SingletonHolder.h" RelativePath=".\include\Poco\SingletonHolder.h"
> >
</File> </File>
<File
RelativePath=".\include\Poco\SmallObjectAllocator.h"
>
</File>
<File <File
RelativePath=".\include\Poco\SortedDirectoryIterator.h" RelativePath=".\include\Poco\SortedDirectoryIterator.h"
> >

View File

@@ -60,7 +60,11 @@ template <class> class VarHolderImpl;
} }
template <typename PlaceholderT, unsigned int SizeV = POCO_SMALL_OBJECT_SIZE> template <typename PlaceholderT
#ifndef POCO_NO_SOO
, unsigned int SizeV = POCO_SMALL_OBJECT_SIZE
#endif
>
union Placeholder union Placeholder
/// ValueHolder union (used by Poco::Any and Poco::Dynamic::Var for small /// ValueHolder union (used by Poco::Any and Poco::Dynamic::Var for small
/// object optimization). /// object optimization).
@@ -112,7 +116,9 @@ public:
#endif #endif
PlaceholderT* pHolder; PlaceholderT* pHolder;
#ifndef POCO_NO_SOO
mutable unsigned char holder[SizeV + 1]; mutable unsigned char holder[SizeV + 1];
#endif
friend class Any; friend class Any;
friend class Dynamic::Var; friend class Dynamic::Var;

View File

@@ -101,15 +101,13 @@
// defined, Any and Dynamic::Var (and similar optimization // defined, Any and Dynamic::Var (and similar optimization
// candidates) will be auto-allocated on the stack in // candidates) will be auto-allocated on the stack in
// cases when value holder fits into POCO_SMALL_OBJECT_SIZE // cases when value holder fits into POCO_SMALL_OBJECT_SIZE
// (see Poco/Types.h for default values). // (see below).
// #define POCO_NO_SOO #define POCO_NO_SOO
// Small object size in bytes. Where applicable (e.g. // Small object size in bytes. When assigned to Any or Var,
// SmallObjectAllocator<char*> specialization, Any, Var, etc)
// objects longer than this value will be alocated on the heap. // objects longer than this value will be alocated on the heap.
// See Poco/SmallObjectAllocator.h for usage of this value. #if !defined(POCO_SMALL_OBJECT_SIZE) && !defined(POCO_NO_SOO)
#if !defined(POCO_SMALL_OBJECT_SIZE)
#define POCO_SMALL_OBJECT_SIZE 32 #define POCO_SMALL_OBJECT_SIZE 32
#endif #endif

View File

@@ -1,251 +0,0 @@
//
// SmallObjectAllocator.h
//
// $Id: //poco/1.4/Foundation/include/Poco/SmallObjectAllocator.h#1 $
//
// Library: Foundation
// Package: Core
// Module: SmallObjectAllocator
//
// Definition of the SmallObjectAllocator template.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Foundation_SmallObjectAllocator_INCLUDED
#define Foundation_SmallObjectAllocator_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/Types.h"
namespace Poco {
template <typename T, std::size_t S = sizeof(T)>
class SmallObjectAllocator
/// SmallObjectAllocator template is a lightweight wrapper implementing
/// small object allocation optimization idiom. Class is statically
/// parameterized on type created and the size threshold, which defaults
/// to the created object size; it follows that the default behavior is
/// use of automatically allocated memory (i.e. the value wrapped is
/// stored in the pre-allocated buffer). To enforce heap allocation,
/// specify S parameter to a value smaller than the size of the type
/// being instantiated.
///
/// The SmallObjectAllocator trade-off is the runtime check for memory
/// location where the value resides. The runtime check occurs at
/// construction/destruction as well as every value access. Value
/// access check can be alleviated by caching the value reference.
///
/// Usage example:
///
/// SmallObjectAllocator<int> s; // on the stack
/// SmallObjectAllocator<int, 1> h; // force heap alloc
/// int& i = s.get(); // no runtime performance penalty after this point
/// i = 5;
///
{
public:
SmallObjectAllocator()
{
if (isOnHeap()) _memory.ptr = new T();
else new (_memory.buf) T;
}
SmallObjectAllocator(const T& val)
{
if (isOnHeap()) _memory.ptr = new T(val);
else new (_memory.buf) T(val);
}
SmallObjectAllocator(const SmallObjectAllocator& other)
{
if (this != &other)
{
if (isOnHeap())
_memory.ptr = new T(*other._memory.ptr);
else
new (_memory.buf) T(*reinterpret_cast<const T*>(other._memory.buf));
}
}
~SmallObjectAllocator()
{
if (isOnHeap()) delete _memory.ptr;
else reinterpret_cast<T*>(_memory.buf)->~T();
}
SmallObjectAllocator& operator =(const SmallObjectAllocator& other)
{
if (this != &other)
{
if (isOnHeap())
_memory.ptr = new T(*other._memory.ptr);
else
new (_memory.buf) T(*reinterpret_cast<const T*>(other._memory.buf));
}
return *this;
}
T& get()
{
if (isOnHeap())
return *_memory.ptr;
else
return reinterpret_cast<T&>(*(_memory.buf));
}
const T& get() const
{
if (isOnHeap())
return *_memory.ptr;
else
return reinterpret_cast<const T&>(*_memory.buf);
}
bool isOnHeap() const
{
return sizeof(T) > S;
}
private:
union
{
unsigned char buf[S];
T* ptr;
} _memory;
};
template <>
class SmallObjectAllocator <char*>
/// SmallObjectAllocator char* specialization.
///
/// The treshold between auto and heap allocation
/// is controlled through POCO_SMALL_OBJECT_SIZE compile
/// time constant, which on 32 or 64-bit systems defaults
/// to 31 or 63 bytes respectively. This specialization
/// adds an extra byte to indicate the allocation strategy.
///
/// To summarize, e.g. POCO_SMALL_OBJECT_SIZE value of 7 will
/// take up at least 8 bytes of storage (for auto allocation)
/// with 6 bytes as the effective string length:
///
/// +---+---+---+---+---+---+---+---+
/// | c | c | c | c | c | c | 0 | f |
/// +---+---+---+---+---+---+---+---+
///
/// Legend:
/// c - character
/// 0 - terminating zero
/// f - allocation flag
///
{
public:
static const std::size_t Size = POCO_SMALL_OBJECT_SIZE;
SmallObjectAllocator(std::size_t sz)
{
_memory.buf[Size] = (sz > Size) ? 1 : 0;
if (_memory.buf[Size]) _memory.ptr = new char[sz + 1];
}
SmallObjectAllocator(const char* pCh, std::size_t sz)
{
allocateAndAssign(pCh, sz);
}
SmallObjectAllocator(const char* pCh)
{
allocateAndAssign(pCh, strlen(pCh));
}
~SmallObjectAllocator()
{
if (_memory.buf[Size]) delete _memory.ptr;
}
SmallObjectAllocator <char*>& operator = (const char* pCh)
{
allocateAndAssign(pCh, strlen(pCh));
return *this;
}
char* get()
{
if (_memory.buf[Size]) return _memory.ptr;
else return _memory.buf;
}
const char* get() const
{
if (_memory.buf[Size]) return _memory.ptr;
else return _memory.buf;
}
bool isOnHeap() const
{
return _memory.buf[Size] != 0;
}
private:
SmallObjectAllocator();
void allocateAndAssign(const char* pCh, std::size_t sz)
{
_memory.buf[Size] = (sz > Size) ? 1 : 0;
if (_memory.buf[Size])
{
_memory.ptr = new char[sz + 1];
_memory.ptr[sz] = '\0';
std::memcpy(_memory.ptr, pCh, sz);
}
else
{
_memory.buf[sz] = '\0';
std::memcpy(_memory.buf, pCh, sz);
}
}
union
{
char buf[Size + 1];
char* ptr;
} _memory;
};
typedef SmallObjectAllocator<char*> SmallStringAllocator;
} // namespace Poco
#endif // Foundation_SmallObjectAllocator_INCLUDED

View File

@@ -45,7 +45,6 @@
#include "Poco/Ascii.h" #include "Poco/Ascii.h"
#include "Poco/BasicEvent.h" #include "Poco/BasicEvent.h"
#include "Poco/Delegate.h" #include "Poco/Delegate.h"
#include "Poco/SmallObjectAllocator.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@@ -65,7 +64,6 @@ using Poco::AtomicCounter;
using Poco::Nullable; using Poco::Nullable;
using Poco::Ascii; using Poco::Ascii;
using Poco::BasicEvent; using Poco::BasicEvent;
using Poco::SmallObjectAllocator;
using Poco::delegate; using Poco::delegate;
using Poco::NullType; using Poco::NullType;
using Poco::InvalidAccessException; using Poco::InvalidAccessException;
@@ -1064,137 +1062,6 @@ void CoreTest::testAscii()
} }
void CoreTest::testSmallObjectAllocator()
{
{
SmallObjectAllocator<int> soa1;
assert (!soa1.isOnHeap());
int& i = soa1.get();
i = 42;
int j = i;
assert (j == 42);
int* pi = &i;
assert (*pi == 42);
*pi = 24;
assert (i == 24);
SmallObjectAllocator<int> soa2(soa1);
assert (soa1.get() == soa2.get());
assert (soa2.get() == 24);
SmallObjectAllocator<int> soa3;
soa3 = soa2;
assert (soa3.get() == soa2.get());
assert (soa3.get() == 24);
}
{
// force heap alloc
SmallObjectAllocator<int, 1> soa1;
assert (soa1.isOnHeap());
int& i = soa1.get();
i = 42;
int j = i;
assert (j == 42);
int* pi = &i;
assert (*pi == 42);
*pi = 24;
assert (i == 24);
SmallObjectAllocator<int, 1> soa2(soa1);
assert (soa1.get() == soa2.get());
assert (soa2.get() == 24);
SmallObjectAllocator<int, 1> soa3;
soa3 = soa2;
assert (soa3.get() == soa2.get());
assert (soa3.get() == 24);
}
SmallObjectAllocator<Small> soa2;
assert (!soa2.isOnHeap());
{
assert (Parent::i == 0);
SmallObjectAllocator<Medium> soa3;
assert (!soa3.isOnHeap());
assert (Parent::i == -1);
}
assert (Parent::i == -2);
{
typedef SmallObjectAllocator<Large, 4> LargeType;
LargeType soa4;
assert (soa4.isOnHeap());
Large large = soa4.get();
assert (large.i == 1);
assert (large.j == 2);
assert (large.k == 3);
const LargeType soa5;
assert (soa5.get().l == 4);
}
Parent::i = 0; // only to make sure subsequent runs don't fail
SmallObjectAllocator<char*> soa6(2);
assert (!soa6.isOnHeap());
char* pC2 = soa6.get();
pC2[0] = 'x';
pC2[1] = '\0';
std::string str2(pC2);
assert (str2 == "x");
std::size_t sz = POCO_SMALL_OBJECT_SIZE + 1;
Poco::SmallStringAllocator soa7(sz);
assert (soa7.isOnHeap());
char* pC = soa7.get();
char c = '0';
int i = 0;
// test this only for default values
if (POCO_SMALL_OBJECT_SIZE == 15)
{
for (i = 0; i < sz - 1; ++i)
pC[i] = c++;
pC[i] = '\0';
std::string str(pC);
assert (str == "0123456789:;<=>");
Poco::SmallStringAllocator soa7("0123456789:;<=>");
assert (str == soa7.get());
soa7 = "";
assert (soa7.get()[0] == '\0');
soa7 = "0123456789:;<=>";
assert (str == soa7.get());
}
else if (POCO_SMALL_OBJECT_SIZE == 7)
{
for (i = 0; i < sz - 1; ++i)
pC[i] = c++;
pC[i] = '\0';
std::string str(pC);
assert (str == "0123456");
Poco::SmallStringAllocator soa7("0123456");
assert (str == soa7.get());
soa7 = "";
assert (soa7.get()[0] == '\0');
soa7 = "0123456";
assert (str == soa7.get());
}
std::string str("0123456789");
Poco::SmallObjectAllocator<std::string> soa8(str);
assert (!soa8.isOnHeap());
assert(soa8.get() == str);
Poco::SmallObjectAllocator<std::string, 1> soa9;
assert (soa9.isOnHeap());
soa9 = str;
assert(soa9.get() == str);
}
void CoreTest::onReadable(bool& b) void CoreTest::onReadable(bool& b)
{ {
if (b) ++_notToReadable; if (b) ++_notToReadable;
@@ -1238,7 +1105,6 @@ CppUnit::Test* CoreTest::suite()
CppUnit_addTest(pSuite, CoreTest, testAtomicCounter); CppUnit_addTest(pSuite, CoreTest, testAtomicCounter);
CppUnit_addTest(pSuite, CoreTest, testNullable); CppUnit_addTest(pSuite, CoreTest, testNullable);
CppUnit_addTest(pSuite, CoreTest, testAscii); CppUnit_addTest(pSuite, CoreTest, testAscii);
CppUnit_addTest(pSuite, CoreTest, testSmallObjectAllocator);
return pSuite; return pSuite;
} }

View File

@@ -58,7 +58,6 @@ public:
void testAtomicCounter(); void testAtomicCounter();
void testNullable(); void testNullable();
void testAscii(); void testAscii();
void testSmallObjectAllocator();
void setUp(); void setUp();
void tearDown(); void tearDown();