diff --git a/Foundation/Foundation_CE_vs90.vcproj b/Foundation/Foundation_CE_vs90.vcproj index f6a0bffdf..73ce94078 100644 --- a/Foundation/Foundation_CE_vs90.vcproj +++ b/Foundation/Foundation_CE_vs90.vcproj @@ -6749,10 +6749,6 @@ RelativePath=".\include\Poco\SingletonHolder.h" > - - diff --git a/Foundation/Foundation_vs100.vcxproj b/Foundation/Foundation_vs100.vcxproj index be570b924..a6bd2d3b6 100644 --- a/Foundation/Foundation_vs100.vcxproj +++ b/Foundation/Foundation_vs100.vcxproj @@ -1040,7 +1040,6 @@ - diff --git a/Foundation/Foundation_vs100.vcxproj.filters b/Foundation/Foundation_vs100.vcxproj.filters index e91994019..b78b65789 100644 --- a/Foundation/Foundation_vs100.vcxproj.filters +++ b/Foundation/Foundation_vs100.vcxproj.filters @@ -1859,9 +1859,6 @@ Streams\Header Files - - Core\Header Files - Core\Header Files diff --git a/Foundation/Foundation_vs110.vcxproj b/Foundation/Foundation_vs110.vcxproj index d24aa1550..ca5f7fa6d 100644 --- a/Foundation/Foundation_vs110.vcxproj +++ b/Foundation/Foundation_vs110.vcxproj @@ -1044,7 +1044,6 @@ - diff --git a/Foundation/Foundation_vs110.vcxproj.filters b/Foundation/Foundation_vs110.vcxproj.filters index 5781661ee..c67bc254f 100644 --- a/Foundation/Foundation_vs110.vcxproj.filters +++ b/Foundation/Foundation_vs110.vcxproj.filters @@ -1049,9 +1049,6 @@ Core\Header Files - - Core\Header Files - Core\Header Files diff --git a/Foundation/Foundation_vs71.vcproj b/Foundation/Foundation_vs71.vcproj index 5b5285c95..c5b5dc9ad 100644 --- a/Foundation/Foundation_vs71.vcproj +++ b/Foundation/Foundation_vs71.vcproj @@ -940,9 +940,6 @@ - - diff --git a/Foundation/Foundation_vs80.vcproj b/Foundation/Foundation_vs80.vcproj index bc6c42062..ef90303af 100644 --- a/Foundation/Foundation_vs80.vcproj +++ b/Foundation/Foundation_vs80.vcproj @@ -1255,10 +1255,6 @@ RelativePath=".\include\Poco\SingletonHolder.h" > - - diff --git a/Foundation/Foundation_vs90.vcproj b/Foundation/Foundation_vs90.vcproj index 54867899e..8e818df87 100644 --- a/Foundation/Foundation_vs90.vcproj +++ b/Foundation/Foundation_vs90.vcproj @@ -1252,10 +1252,6 @@ RelativePath=".\include\Poco\SingletonHolder.h" > - - diff --git a/Foundation/Foundation_x64_vs100.vcxproj b/Foundation/Foundation_x64_vs100.vcxproj index 0530a9b56..da7208465 100644 --- a/Foundation/Foundation_x64_vs100.vcxproj +++ b/Foundation/Foundation_x64_vs100.vcxproj @@ -1042,7 +1042,6 @@ - diff --git a/Foundation/Foundation_x64_vs100.vcxproj.filters b/Foundation/Foundation_x64_vs100.vcxproj.filters index 4aabee286..0457c3839 100644 --- a/Foundation/Foundation_x64_vs100.vcxproj.filters +++ b/Foundation/Foundation_x64_vs100.vcxproj.filters @@ -1868,9 +1868,6 @@ Text\Header Files - - Core\Header Files - diff --git a/Foundation/Foundation_x64_vs110.vcxproj b/Foundation/Foundation_x64_vs110.vcxproj index 0356aac84..7a1fa1bd7 100644 --- a/Foundation/Foundation_x64_vs110.vcxproj +++ b/Foundation/Foundation_x64_vs110.vcxproj @@ -1049,7 +1049,6 @@ - diff --git a/Foundation/Foundation_x64_vs110.vcxproj.filters b/Foundation/Foundation_x64_vs110.vcxproj.filters index 7c27a6012..0457c3839 100644 --- a/Foundation/Foundation_x64_vs110.vcxproj.filters +++ b/Foundation/Foundation_x64_vs110.vcxproj.filters @@ -1052,9 +1052,6 @@ Core\Header Files - - Core\Header Files - Core\Header Files diff --git a/Foundation/Foundation_x64_vs90.vcproj b/Foundation/Foundation_x64_vs90.vcproj index 38145843b..96b420712 100644 --- a/Foundation/Foundation_x64_vs90.vcproj +++ b/Foundation/Foundation_x64_vs90.vcproj @@ -1250,10 +1250,6 @@ RelativePath=".\include\Poco\SingletonHolder.h" > - - diff --git a/Foundation/include/Poco/Any.h b/Foundation/include/Poco/Any.h index 05acb5f4a..ce26cfd7d 100644 --- a/Foundation/include/Poco/Any.h +++ b/Foundation/include/Poco/Any.h @@ -60,7 +60,11 @@ template class VarHolderImpl; } -template +template union Placeholder /// ValueHolder union (used by Poco::Any and Poco::Dynamic::Var for small /// object optimization). @@ -112,7 +116,9 @@ public: #endif PlaceholderT* pHolder; +#ifndef POCO_NO_SOO mutable unsigned char holder[SizeV + 1]; +#endif friend class Any; friend class Dynamic::Var; diff --git a/Foundation/include/Poco/Config.h b/Foundation/include/Poco/Config.h index 0194ba4a9..3d775e172 100644 --- a/Foundation/include/Poco/Config.h +++ b/Foundation/include/Poco/Config.h @@ -101,15 +101,13 @@ // defined, Any and Dynamic::Var (and similar optimization // candidates) will be auto-allocated on the stack in // cases when value holder fits into POCO_SMALL_OBJECT_SIZE -// (see Poco/Types.h for default values). -// #define POCO_NO_SOO +// (see below). +#define POCO_NO_SOO -// Small object size in bytes. Where applicable (e.g. -// SmallObjectAllocator specialization, Any, Var, etc) +// Small object size in bytes. When assigned to Any or Var, // 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) +#if !defined(POCO_SMALL_OBJECT_SIZE) && !defined(POCO_NO_SOO) #define POCO_SMALL_OBJECT_SIZE 32 #endif diff --git a/Foundation/include/Poco/SmallObjectAllocator.h b/Foundation/include/Poco/SmallObjectAllocator.h deleted file mode 100644 index f30ba438b..000000000 --- a/Foundation/include/Poco/SmallObjectAllocator.h +++ /dev/null @@ -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 -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 s; // on the stack - /// SmallObjectAllocator 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(other._memory.buf)); - } - } - - ~SmallObjectAllocator() - { - if (isOnHeap()) delete _memory.ptr; - else reinterpret_cast(_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(other._memory.buf)); - } - - return *this; - } - - T& get() - { - if (isOnHeap()) - return *_memory.ptr; - else - return reinterpret_cast(*(_memory.buf)); - } - - const T& get() const - { - if (isOnHeap()) - return *_memory.ptr; - else - return reinterpret_cast(*_memory.buf); - } - - bool isOnHeap() const - { - return sizeof(T) > S; - } - -private: - union - { - unsigned char buf[S]; - T* ptr; - } _memory; -}; - - -template <> -class SmallObjectAllocator - /// 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 & 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 SmallStringAllocator; - - -} // namespace Poco - - -#endif // Foundation_SmallObjectAllocator_INCLUDED diff --git a/Foundation/testsuite/src/CoreTest.cpp b/Foundation/testsuite/src/CoreTest.cpp index 78187e8e9..6853bf3f0 100644 --- a/Foundation/testsuite/src/CoreTest.cpp +++ b/Foundation/testsuite/src/CoreTest.cpp @@ -45,7 +45,6 @@ #include "Poco/Ascii.h" #include "Poco/BasicEvent.h" #include "Poco/Delegate.h" -#include "Poco/SmallObjectAllocator.h" #include "Poco/Exception.h" #include #include @@ -65,7 +64,6 @@ using Poco::AtomicCounter; using Poco::Nullable; using Poco::Ascii; using Poco::BasicEvent; -using Poco::SmallObjectAllocator; using Poco::delegate; using Poco::NullType; using Poco::InvalidAccessException; @@ -1064,137 +1062,6 @@ void CoreTest::testAscii() } -void CoreTest::testSmallObjectAllocator() -{ - { - SmallObjectAllocator 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 soa2(soa1); - assert (soa1.get() == soa2.get()); - assert (soa2.get() == 24); - - SmallObjectAllocator soa3; - soa3 = soa2; - assert (soa3.get() == soa2.get()); - assert (soa3.get() == 24); - } - { - // force heap alloc - SmallObjectAllocator 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 soa2(soa1); - assert (soa1.get() == soa2.get()); - assert (soa2.get() == 24); - - SmallObjectAllocator soa3; - soa3 = soa2; - assert (soa3.get() == soa2.get()); - assert (soa3.get() == 24); - } - - SmallObjectAllocator soa2; - assert (!soa2.isOnHeap()); - - { - assert (Parent::i == 0); - SmallObjectAllocator soa3; - assert (!soa3.isOnHeap()); - assert (Parent::i == -1); - } - assert (Parent::i == -2); - - { - typedef SmallObjectAllocator 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 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 soa8(str); - assert (!soa8.isOnHeap()); - assert(soa8.get() == str); - - Poco::SmallObjectAllocator soa9; - assert (soa9.isOnHeap()); - soa9 = str; - assert(soa9.get() == str); -} - - void CoreTest::onReadable(bool& b) { if (b) ++_notToReadable; @@ -1238,7 +1105,6 @@ CppUnit::Test* CoreTest::suite() CppUnit_addTest(pSuite, CoreTest, testAtomicCounter); CppUnit_addTest(pSuite, CoreTest, testNullable); CppUnit_addTest(pSuite, CoreTest, testAscii); - CppUnit_addTest(pSuite, CoreTest, testSmallObjectAllocator); return pSuite; } diff --git a/Foundation/testsuite/src/CoreTest.h b/Foundation/testsuite/src/CoreTest.h index 4d4eed110..a521fce91 100644 --- a/Foundation/testsuite/src/CoreTest.h +++ b/Foundation/testsuite/src/CoreTest.h @@ -58,7 +58,6 @@ public: void testAtomicCounter(); void testNullable(); void testAscii(); - void testSmallObjectAllocator(); void setUp(); void tearDown();