]> git.lyx.org Git - features.git/blobdiff - boost/boost/smart_ptr/detail/quick_allocator.hpp
boost: add eol property
[features.git] / boost / boost / smart_ptr / detail / quick_allocator.hpp
index 5025f52259de849e3bb88201f20162c0779fcc0f..6d136f82d73f2dbb25561260ecd9d0aa6c1978c3 100644 (file)
-#ifndef BOOST_SMART_PTR_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED\r
-#define BOOST_SMART_PTR_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED\r
-\r
-// MS compatible compilers support #pragma once\r
-\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)\r
-# pragma once\r
-#endif\r
-\r
-//\r
-//  detail/quick_allocator.hpp\r
-//\r
-//  Copyright (c) 2003 David Abrahams\r
-//  Copyright (c) 2003 Peter Dimov\r
-//\r
-// Distributed under the Boost Software License, Version 1.0. (See\r
-// accompanying file LICENSE_1_0.txt or copy at\r
-// http://www.boost.org/LICENSE_1_0.txt)\r
-//\r
-\r
-#include <boost/config.hpp>\r
-\r
-#include <boost/smart_ptr/detail/lightweight_mutex.hpp>\r
-#include <boost/type_traits/type_with_alignment.hpp>\r
-#include <boost/type_traits/alignment_of.hpp>\r
-\r
-#include <new>              // ::operator new, ::operator delete\r
-#include <cstddef>          // std::size_t\r
-\r
-namespace boost\r
-{\r
-\r
-namespace detail\r
-{\r
-\r
-template<unsigned size, unsigned align_> union freeblock\r
-{\r
-    typedef typename boost::type_with_alignment<align_>::type aligner_type;\r
-    aligner_type aligner;\r
-    char bytes[size];\r
-    freeblock * next;\r
-};\r
-\r
-template<unsigned size, unsigned align_> struct allocator_impl\r
-{\r
-    typedef freeblock<size, align_> block;\r
-\r
-    // It may seem odd to use such small pages.\r
-    //\r
-    // However, on a typical Windows implementation that uses\r
-    // the OS allocator, "normal size" pages interact with the\r
-    // "ordinary" operator new, slowing it down dramatically.\r
-    //\r
-    // 512 byte pages are handled by the small object allocator,\r
-    // and don't interfere with ::new.\r
-    //\r
-    // The other alternative is to use much bigger pages (1M.)\r
-    //\r
-    // It is surprisingly easy to hit pathological behavior by\r
-    // varying the page size. g++ 2.96 on Red Hat Linux 7.2,\r
-    // for example, passionately dislikes 496. 512 seems OK.\r
-\r
-#if defined(BOOST_QA_PAGE_SIZE)\r
-\r
-    enum { items_per_page = BOOST_QA_PAGE_SIZE / size };\r
-\r
-#else\r
-\r
-    enum { items_per_page = 512 / size }; // 1048560 / size\r
-\r
-#endif\r
-\r
-#ifdef BOOST_HAS_THREADS\r
-\r
-    static lightweight_mutex & mutex()\r
-    {\r
-        static lightweight_mutex m;\r
-        return m;\r
-    }\r
-\r
-    static lightweight_mutex * mutex_init;\r
-\r
-#endif\r
-\r
-    static block * free;\r
-    static block * page;\r
-    static unsigned last;\r
-\r
-    static inline void * alloc()\r
-    {\r
-#ifdef BOOST_HAS_THREADS\r
-        lightweight_mutex::scoped_lock lock( mutex() );\r
-#endif\r
-        if(block * x = free)\r
-        {\r
-            free = x->next;\r
-            return x;\r
-        }\r
-        else\r
-        {\r
-            if(last == items_per_page)\r
-            {\r
-                // "Listen to me carefully: there is no memory leak"\r
-                // -- Scott Meyers, Eff C++ 2nd Ed Item 10\r
-                page = ::new block[items_per_page];\r
-                last = 0;\r
-            }\r
-\r
-            return &page[last++];\r
-        }\r
-    }\r
-\r
-    static inline void * alloc(std::size_t n)\r
-    {\r
-        if(n != size) // class-specific new called for a derived object\r
-        {\r
-            return ::operator new(n);\r
-        }\r
-        else\r
-        {\r
-#ifdef BOOST_HAS_THREADS\r
-            lightweight_mutex::scoped_lock lock( mutex() );\r
-#endif\r
-            if(block * x = free)\r
-            {\r
-                free = x->next;\r
-                return x;\r
-            }\r
-            else\r
-            {\r
-                if(last == items_per_page)\r
-                {\r
-                    page = ::new block[items_per_page];\r
-                    last = 0;\r
-                }\r
-\r
-                return &page[last++];\r
-            }\r
-        }\r
-    }\r
-\r
-    static inline void dealloc(void * pv)\r
-    {\r
-        if(pv != 0) // 18.4.1.1/13\r
-        {\r
-#ifdef BOOST_HAS_THREADS\r
-            lightweight_mutex::scoped_lock lock( mutex() );\r
-#endif\r
-            block * pb = static_cast<block *>(pv);\r
-            pb->next = free;\r
-            free = pb;\r
-        }\r
-    }\r
-\r
-    static inline void dealloc(void * pv, std::size_t n)\r
-    {\r
-        if(n != size) // class-specific delete called for a derived object\r
-        {\r
-            ::operator delete(pv);\r
-        }\r
-        else if(pv != 0) // 18.4.1.1/13\r
-        {\r
-#ifdef BOOST_HAS_THREADS\r
-            lightweight_mutex::scoped_lock lock( mutex() );\r
-#endif\r
-            block * pb = static_cast<block *>(pv);\r
-            pb->next = free;\r
-            free = pb;\r
-        }\r
-    }\r
-};\r
-\r
-#ifdef BOOST_HAS_THREADS\r
-\r
-template<unsigned size, unsigned align_>\r
-  lightweight_mutex * allocator_impl<size, align_>::mutex_init = &allocator_impl<size, align_>::mutex();\r
-\r
-#endif\r
-\r
-template<unsigned size, unsigned align_>\r
-  freeblock<size, align_> * allocator_impl<size, align_>::free = 0;\r
-\r
-template<unsigned size, unsigned align_>\r
-  freeblock<size, align_> * allocator_impl<size, align_>::page = 0;\r
-\r
-template<unsigned size, unsigned align_>\r
-  unsigned allocator_impl<size, align_>::last = allocator_impl<size, align_>::items_per_page;\r
-\r
-template<class T>\r
-struct quick_allocator: public allocator_impl< sizeof(T), boost::alignment_of<T>::value >\r
-{\r
-};\r
-\r
-} // namespace detail\r
-\r
-} // namespace boost\r
-\r
-#endif  // #ifndef BOOST_SMART_PTR_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED\r
+#ifndef BOOST_SMART_PTR_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED
+#define BOOST_SMART_PTR_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED
+
+// MS compatible compilers support #pragma once
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+//
+//  detail/quick_allocator.hpp
+//
+//  Copyright (c) 2003 David Abrahams
+//  Copyright (c) 2003 Peter Dimov
+//
+// 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)
+//
+
+#include <boost/config.hpp>
+
+#include <boost/smart_ptr/detail/lightweight_mutex.hpp>
+#include <boost/type_traits/type_with_alignment.hpp>
+#include <boost/type_traits/alignment_of.hpp>
+
+#include <new>              // ::operator new, ::operator delete
+#include <cstddef>          // std::size_t
+
+namespace boost
+{
+
+namespace detail
+{
+
+template<unsigned size, unsigned align_> union freeblock
+{
+    typedef typename boost::type_with_alignment<align_>::type aligner_type;
+    aligner_type aligner;
+    char bytes[size];
+    freeblock * next;
+};
+
+template<unsigned size, unsigned align_> struct allocator_impl
+{
+    typedef freeblock<size, align_> block;
+
+    // It may seem odd to use such small pages.
+    //
+    // However, on a typical Windows implementation that uses
+    // the OS allocator, "normal size" pages interact with the
+    // "ordinary" operator new, slowing it down dramatically.
+    //
+    // 512 byte pages are handled by the small object allocator,
+    // and don't interfere with ::new.
+    //
+    // The other alternative is to use much bigger pages (1M.)
+    //
+    // It is surprisingly easy to hit pathological behavior by
+    // varying the page size. g++ 2.96 on Red Hat Linux 7.2,
+    // for example, passionately dislikes 496. 512 seems OK.
+
+#if defined(BOOST_QA_PAGE_SIZE)
+
+    enum { items_per_page = BOOST_QA_PAGE_SIZE / size };
+
+#else
+
+    enum { items_per_page = 512 / size }; // 1048560 / size
+
+#endif
+
+#ifdef BOOST_HAS_THREADS
+
+    static lightweight_mutex & mutex()
+    {
+        static lightweight_mutex m;
+        return m;
+    }
+
+    static lightweight_mutex * mutex_init;
+
+#endif
+
+    static block * free;
+    static block * page;
+    static unsigned last;
+
+    static inline void * alloc()
+    {
+#ifdef BOOST_HAS_THREADS
+        lightweight_mutex::scoped_lock lock( mutex() );
+#endif
+        if(block * x = free)
+        {
+            free = x->next;
+            return x;
+        }
+        else
+        {
+            if(last == items_per_page)
+            {
+                // "Listen to me carefully: there is no memory leak"
+                // -- Scott Meyers, Eff C++ 2nd Ed Item 10
+                page = ::new block[items_per_page];
+                last = 0;
+            }
+
+            return &page[last++];
+        }
+    }
+
+    static inline void * alloc(std::size_t n)
+    {
+        if(n != size) // class-specific new called for a derived object
+        {
+            return ::operator new(n);
+        }
+        else
+        {
+#ifdef BOOST_HAS_THREADS
+            lightweight_mutex::scoped_lock lock( mutex() );
+#endif
+            if(block * x = free)
+            {
+                free = x->next;
+                return x;
+            }
+            else
+            {
+                if(last == items_per_page)
+                {
+                    page = ::new block[items_per_page];
+                    last = 0;
+                }
+
+                return &page[last++];
+            }
+        }
+    }
+
+    static inline void dealloc(void * pv)
+    {
+        if(pv != 0) // 18.4.1.1/13
+        {
+#ifdef BOOST_HAS_THREADS
+            lightweight_mutex::scoped_lock lock( mutex() );
+#endif
+            block * pb = static_cast<block *>(pv);
+            pb->next = free;
+            free = pb;
+        }
+    }
+
+    static inline void dealloc(void * pv, std::size_t n)
+    {
+        if(n != size) // class-specific delete called for a derived object
+        {
+            ::operator delete(pv);
+        }
+        else if(pv != 0) // 18.4.1.1/13
+        {
+#ifdef BOOST_HAS_THREADS
+            lightweight_mutex::scoped_lock lock( mutex() );
+#endif
+            block * pb = static_cast<block *>(pv);
+            pb->next = free;
+            free = pb;
+        }
+    }
+};
+
+#ifdef BOOST_HAS_THREADS
+
+template<unsigned size, unsigned align_>
+  lightweight_mutex * allocator_impl<size, align_>::mutex_init = &allocator_impl<size, align_>::mutex();
+
+#endif
+
+template<unsigned size, unsigned align_>
+  freeblock<size, align_> * allocator_impl<size, align_>::free = 0;
+
+template<unsigned size, unsigned align_>
+  freeblock<size, align_> * allocator_impl<size, align_>::page = 0;
+
+template<unsigned size, unsigned align_>
+  unsigned allocator_impl<size, align_>::last = allocator_impl<size, align_>::items_per_page;
+
+template<class T>
+struct quick_allocator: public allocator_impl< sizeof(T), boost::alignment_of<T>::value >
+{
+};
+
+} // namespace detail
+
+} // namespace boost
+
+#endif  // #ifndef BOOST_SMART_PTR_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED