src/Emu/Utility/System/Memory/HeapAllocator.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 #ifndef __EMULATORUTILITY_HEAPALLOCATOR_H__
00033 #define __EMULATORUTILITY_HEAPALLOCATOR_H__
00034 
00035 namespace Onikiri {
00036     namespace EmulatorUtility {
00037 
00038         // ^[Qbgq[v
00039         // 
00040         // AhX (s)
00041         // my[WPs
00042         class HeapAllocator
00043         {
00044         private:
00045             HeapAllocator() {}
00046         public:
00047             // pageSize
00048             explicit HeapAllocator(u64 pageSize);
00049 
00050             // AhXstartlengthoCgCHeapAllocatorgpij
00051             bool AddMemoryBlock(u64 start, u64 length);
00052 
00053             // addrAhXlengthoCgm
00054             // addr0CKAhXm
00055             //
00056             // l: mAhXD0G[
00057             //        AhXy[WE
00058             u64 Alloc(u64 addr, u64 length);
00059 
00060             // addrumTCY old_size  new_size X
00061             //
00062             // l: AhXD0G[
00063             //        AhXy[WE
00064             u64 ReAlloc(u64 old_addr, u64 old_size, u64 new_size);
00065 
00066             // AllocJ
00067             // l: trueCクsfalse (ubNn)
00068             bool Free(u64 addr);
00069             // AllocSJ
00070             bool Free(u64 addr, u64 size);
00071 
00072             // addr AllocTCY
00073             u64 GetBlockSize(u64 addr) const;
00074 
00075             // addr m
00076             u64 IsIntersected(u64 addr, u64 length) const;
00077 
00078             u64 GetPageSize() const { return m_pageSize; }
00079 
00080         private:
00081             struct MemoryBlock
00082             {
00083                 u64 Addr;
00084                 u64 Bytes;
00085 
00086                 explicit MemoryBlock(u64 addr_arg = 0, u64 bytes_arg = 0) : Addr(addr_arg), Bytes(bytes_arg) { }
00087                 bool operator<(const MemoryBlock& mb) const{
00088                     return Addr < mb.Addr;
00089                 }
00090                 bool operator==(const MemoryBlock& mb) const {
00091                     return Addr == mb.Addr;
00092                 }
00093                 bool Intersects(const MemoryBlock& mb) const {
00094                     return (Addr <= mb.Addr && mb.Addr < Addr+Bytes)
00095                         || (mb.Addr <= Addr && Addr < mb.Addr+mb.Bytes);
00096                 }
00097                 bool Contains(const MemoryBlock& mb) const {
00098                     return (Addr <= mb.Addr && mb.Addr+mb.Bytes < Addr+Bytes);
00099                 }
00100             };
00101             typedef std::list<MemoryBlock> BlockList;
00102 
00103             // m_freeList1
00104             void IntegrateFreeBlocks();
00105             BlockList::iterator FindMemoryBlock(BlockList& blockList, u64 addr);
00106             BlockList::const_iterator FindMemoryBlock(const BlockList& blockList, u64 addr) const;
00107 
00108 
00109             u64 in_pages(u64 bytes) const {
00110                 return (bytes + m_pageSize - 1)/m_pageSize;
00111             }
00112 
00113             // free listu
00114             // targetjmmap
00115             BlockList m_freeList;
00116             BlockList m_allocList;
00117             u64 m_pageSize;
00118         };
00119 
00120     } // namespace EmulatorUtility
00121 } // namespace Onikiri
00122 
00123 #endif

Onikiri2に対してTue Jun 18 14:34:20 2013に生成されました。  doxygen 1.4.7