• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            自己實(shí)現(xiàn)的一個(gè)ACE內(nèi)存分配器

            針對(duì)我的前兩篇文章《基于ACE實(shí)現(xiàn)的一個(gè)內(nèi)存池》和《基于ACE實(shí)現(xiàn)的一個(gè)內(nèi)存池-續(xù)篇》后,發(fā)現(xiàn)緩存ACE_Message_Block的時(shí)候還是不太方便,然后干脆實(shí)現(xiàn)了ACE_Allocator接口,代碼如下,利用這個(gè)分配器的ACE_Message_Block將會(huì)很快貼出來。

            //MemPoolAllocator.h
            /**
             *    @date 2007.10.29
             *  @author PeakGao <peakgao163@163.com>
             
            */

            #ifndef OM_MEMPOOLALLOCATOR_H
            #define OM_MEMPOOLALLOCATOR_H

            #include 
            <ace/pre.h>

            //#include <ace/ACE_export.h>

            #if !defined (ACE_LACKS_PRAGMA_ONCE)
            # pragma once
            #endif /* ACE_LACKS_PRAGMA_ONCE */

            #include 
            <ace/Malloc_Base.h>

            #if defined (ACE_HAS_MALLOC_STATS)
            #if defined (ACE_HAS_THREADS)
            #include 
            "ace/Process_Mutex.h"
            #define ACE_PROCESS_MUTEX ACE_Process_Mutex
            #else
            #include 
            "ace/SV_Semaphore_Simple.h"
            #define ACE_PROCESS_MUTEX ACE_SV_Semaphore_Simple
            #endif /* ACE_HAS_THREADS */

            #endif /* ACE_HAS_MALLOC_STATS */

            #include 
            "MemPoolT.h"


            namespace om{

            class My_Allocator : public ACE_Allocator, public CachePool
            {
            public:
              
            /// These methods are defined.
              virtual void *malloc (size_t nbytes);
              
            virtual void *calloc (size_t nbytes, char initial_value = '\0');
              
            virtual void *calloc (size_t n_elem, size_t elem_size, char initial_value = '\0');
              
            virtual void free (void *ptr);

              
            /// These methods are no-ops.
              virtual int remove (void);
              
            virtual int bind (const char *name, void *pointer, int duplicates = 0);
              
            virtual int trybind (const char *name, void *&pointer);
              
            virtual int find (const char *name, void *&pointer);
              
            virtual int find (const char *name);
              
            virtual int unbind (const char *name);
              
            virtual int unbind (const char *name, void *&pointer);
              
            virtual int sync (ssize_t len = -1int flags = MS_SYNC);
              
            virtual int sync (void *addr, size_t len, int flags = MS_SYNC);
              
            virtual int protect (ssize_t len = -1int prot = PROT_RDWR);
              
            virtual int protect (void *addr, size_t len, int prot = PROT_RDWR);
            #if defined (ACE_HAS_MALLOC_STATS)
              
            virtual void print_stats (voidconst;
            #endif /* ACE_HAS_MALLOC_STATS */
              
            virtual void dump (voidconst;

            private:
              
            // DO NOT ADD ANY STATE (DATA MEMBERS) TO THIS CLASS!!!!  See the
              
            // <ACE_Allocator::instance> implementation for explanation.
            }
            ;


            #include 
            /**/ <ace/post.h>

            }
             // namespace om

            #endif // OM_MEMPOOLALLOCATOR_H


            // MemPoolAllocator.cpp
            /**
             *    @date 2007.10.29
             *  @author PeakGao <peakgao163@163.com>
             
            */

             
            #include 
            "MemPoolAllocator.h"
            #include 
            <ace/OS_NS_string.h>

            namespace om{

                
            void *
                My_Allocator::malloc (size_t nbytes)
                
            {
                    
            if (nbytes > 0 && nbytes <= CachePool::getBlockSize())
                      
            return CachePool::alloc();

                  
            return NULL;
                }


                
            void *
                My_Allocator::calloc (size_t nbytes,
                                           
            char initial_value)
                
            {
                  
            void *ptr = malloc(nbytes);
                  
            if (!ptr)
                      
            return NULL;

                  ACE_OS::memset (ptr, initial_value, nbytes);
                  
            return (void *) ptr;
                }


                
            void *
                My_Allocator::calloc (size_t n_elem, size_t elem_size, 
            char initial_value)
                
            {
                  
            return My_Allocator::calloc (n_elem * elem_size, initial_value);
                }


                
            void
                My_Allocator::free (
            void *ptr)
                
            {
                    CachePool::free(ptr);
                }


                
            int
                My_Allocator::remove (
            void)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::bind (
            const char *void *int)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::trybind (
            const char *void *&)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::find (
            const char *void *&)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::find (
            const char *)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::unbind (
            const char *)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::unbind (
            const char *void *&)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::sync (ssize_t, 
            int)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::sync (
            void *, size_t, int)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::protect (ssize_t, 
            int)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            int
                My_Allocator::protect (
            void *, size_t, int)
                
            {
                  ACE_NOTSUP_RETURN (
            -1);
                }


                
            #if defined (ACE_HAS_MALLOC_STATS)
                
            void
                My_Allocator::print_stats (
            voidconst
                
            {
                }

                
            #endif /* ACE_HAS_MALLOC_STATS */

                
            void
                My_Allocator::dump (
            voidconst
                
            {
                
            #if defined (ACE_HAS_DUMP)
                
            #endif /* ACE_HAS_DUMP */
                }



            }
             // namespace om

            posted on 2007-10-29 12:48 PeakGao 閱讀(1968) 評(píng)論(1)  編輯 收藏 引用 所屬分類: C++技術(shù)

            評(píng)論

            # re: 自己實(shí)現(xiàn)的一個(gè)ACE內(nèi)存分配器 2008-03-14 23:27 happychui

            1 class My_Allocator 繼承CachePool時(shí)必須要模版實(shí)例化才行,所以必須加上<ACE_SYNCH_MUTEX>
            2 因?yàn)锳CE_SYNCH_MUTEX需要頭文件 Task.h所以加上了。
              回復(fù)  更多評(píng)論   

            <2007年10月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(9)

            隨筆分類(67)

            隨筆檔案(65)

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲精品高清久久| 久久男人Av资源网站无码软件| 亚洲欧美成人综合久久久| 人人狠狠综合久久亚洲88| 人妻少妇久久中文字幕| 色欲综合久久躁天天躁蜜桃| 中文字幕久久精品无码| 久久伊人五月丁香狠狠色| 久久久国产精华液| 国产成人精品综合久久久久| 国内精品久久久久久久久电影网| 精品多毛少妇人妻AV免费久久| 热99RE久久精品这里都是精品免费 | 久久久国产精华液| 免费久久人人爽人人爽av| 伊人久久久AV老熟妇色| 无码久久精品国产亚洲Av影片| 久久久久亚洲AV无码麻豆| 国产成人精品久久一区二区三区| 久久综合九色综合精品| 国产精品99久久久久久www| 久久天天躁狠狠躁夜夜2020| 久久青青草视频| 69SEX久久精品国产麻豆| 久久久免费观成人影院| 久久99精品国产麻豆宅宅| 国产综合久久久久| 蜜臀久久99精品久久久久久| 一本久久a久久精品vr综合| 99久久婷婷国产综合精品草原| 人妻精品久久久久中文字幕| 色8久久人人97超碰香蕉987| 久久成人影院精品777| 色综合久久天天综线观看| 久久国产精品77777| 婷婷久久综合九色综合九七| 久久人人爽人人爽人人AV| 久久久这里有精品中文字幕| 999久久久无码国产精品| 无码精品久久一区二区三区| 久久免费小视频|