ucommon
7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
![]() ![]() |
#include <memory.h>
Classes | |
struct | mempage |
Public Member Functions | |
memalloc (size_t page=0) | |
memalloc (const memalloc ©) | |
virtual | ~memalloc () |
unsigned | pages (void) const |
unsigned | max (void) const |
size_t | size (void) const |
unsigned | utilization (void) const |
void | purge (void) |
void | assign (memalloc &source) |
Protected Member Functions | |
page_t * | pager (void) |
virtual void * | _alloc (size_t size) __OVERRIDE |
Protected Attributes | |
unsigned | limit |
Private Types | |
typedef struct ucommon::memalloc::mempage | page_t |
Private Attributes | |
size_t | pagesize |
size_t | align |
unsigned | count |
page_t * | page |
Friends | |
class | bufpager |
A memory protocol pager for private heap manager. This is used to allocate in an optimized manner, as it assumes no mutex locks are held or used as part of it's own internal processing. It also is designed for optimized performance.
|
private |
ucommon::memalloc::memalloc | ( | size_t | page = 0 | ) |
ucommon::memalloc::memalloc | ( | const memalloc & | copy | ) |
Definition at line 110 of file memory.cpp.
References align, ucommon::copy(), count, limit, page, and pagesize.
|
virtual |
Destroy a memory pager. Release all pages back to the heap at once.
Definition at line 119 of file memory.cpp.
References purge().
|
protectedvirtual |
Allocate memory from the pager heap. The size of the request must be less than the size of the memory page used. This implements the memory protocol allocation method.
size | of memory request. |
Reimplemented in ucommon::mempager.
Definition at line 202 of file memory.cpp.
References __THROW_SIZE, caddr_t, ucommon::memalloc::mempage::next, page, pager(), pagesize, size(), and ucommon::memalloc::mempage::used.
Referenced by ucommon::mempager::_alloc(), ucommon::ObjectPager::add(), ucommon::StringPager::add(), ost::MemPager::alloc(), ucommon::ObjectPager::list(), ucommon::StringPager::list(), ucommon::ObjectPager::push(), ucommon::StringPager::push(), and ucommon::StringPager::set().
void ucommon::memalloc::assign | ( | memalloc & | source | ) |
Assign foreign pager to us. This relocates the heap references to our object, clears the other object.
Definition at line 59 of file memory.cpp.
References align, count, limit, page, pagesize, and purge().
Referenced by ucommon::mempager::assign(), ucommon::keyfile::assign(), ucommon::ObjectPager::assign(), and ucommon::StringPager::assign().
|
inline |
Get the maximum number of pages that are permitted. One can use a derived class to set and enforce a maximum limit to the number of pages that will be allocated from the real heap. This is often used to detect and bring down apps that are leaking.
Definition at line 117 of file memory.h.
References ucommon::limit().
Referenced by ucommon::shell::detach(), ucommon::shell::priority(), ucommon::shell::spawn(), and ucommon::shell::system().
|
protected |
Acquire a new page from the heap. This is mostly used internally.
Definition at line 161 of file memory.cpp.
References __THROW_ALLOC, __THROW_RUNTIME, ucommon::addr(), align, count, limit, ucommon::memalloc::mempage::next, page, pagesize, and ucommon::memalloc::mempage::used.
Referenced by _alloc().
|
inline |
Get the number of pages that have been allocated from the real heap.
Definition at line 106 of file memory.h.
Referenced by ucommon::ObjectPager::pages(), ucommon::StringPager::pages(), and ucommon::DirPager::pages().
void ucommon::memalloc::purge | ( | void | ) |
Purge all allocated memory and heap pages immediately.
Definition at line 143 of file memory.cpp.
References align, count, ucommon::memalloc::mempage::next, and page.
Referenced by assign(), ucommon::ObjectPager::clear(), ucommon::StringPager::clear(), ost::MemPager::purge(), ucommon::mempager::purge(), ucommon::keyfile::release(), ~memalloc(), and ucommon::mempager::~mempager().
|
inline |
Get the size of a memory page.
Definition at line 125 of file memory.h.
Referenced by _alloc(), ucommon::mempager::_alloc(), ost::SharedMemPager::alloc(), ucommon::shell::getline(), ucommon::shell::getpass(), ucommon::keyfile::load(), ucommon::ObjectPager::size(), ucommon::StringPager::size(), and ucommon::DirPager::size().
unsigned ucommon::memalloc::utilization | ( | void | ) | const |
Determine fragmentation level of acquired heap pages. This is represented as an average % utilization (0-100) and represents the used portion of each allocated heap page verse the page size. Since requests that cannot fit on an already allocated page are moved into a new page, there is some unusable space left over at the end of the page. When utilization approaches 100, this is good. A low utilization may suggest a larger page size should be used.
Definition at line 124 of file memory.cpp.
References ucommon::memalloc::mempage::next, page, pagesize, and ucommon::memalloc::mempage::used.
Referenced by ucommon::mempager::utilization().
|
private |
|
private |
|
protected |
Definition at line 80 of file memory.h.
Referenced by assign(), memalloc(), and pager().
|
private |
Definition at line 77 of file memory.h.
Referenced by _alloc(), assign(), memalloc(), pager(), purge(), and utilization().
|
private |
Definition at line 66 of file memory.h.
Referenced by _alloc(), assign(), memalloc(), pager(), and utilization().