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..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

ucommon::memalloc Class Reference

#include <memory.h>

Inheritance diagram for ucommon::memalloc:
[legend]
Collaboration diagram for ucommon::memalloc:
[legend]

Classes

struct  mempage
 

Public Member Functions

 memalloc (size_t page=0)
 
 memalloc (const memalloc &copy)
 
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_tpager (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_tpage
 

Friends

class bufpager
 

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 61 of file memory.h.

Member Typedef Documentation

◆ page_t

Constructor & Destructor Documentation

◆ memalloc() [1/2]

ucommon::memalloc::memalloc ( size_t  page = 0)

Construct a memory pager.

Parameters
pagesize to use or 0 for OS allocation size.

Definition at line 71 of file memory.cpp.

References align, count, limit, page, and pagesize.

◆ memalloc() [2/2]

ucommon::memalloc::memalloc ( const memalloc copy)

Definition at line 110 of file memory.cpp.

References align, ucommon::copy(), count, limit, page, and pagesize.

◆ ~memalloc()

ucommon::memalloc::~memalloc ( )
virtual

Destroy a memory pager. Release all pages back to the heap at once.

Definition at line 119 of file memory.cpp.

References purge().

Member Function Documentation

◆ _alloc()

void * ucommon::memalloc::_alloc ( size_t  size)
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.

Parameters
sizeof memory request.
Returns
allocated memory or NULL if not possible.

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().

◆ assign()

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().

◆ max()

unsigned ucommon::memalloc::max ( void  ) const
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.

Returns
page allocation limit.

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().

◆ pager()

memalloc::page_t * ucommon::memalloc::pager ( void  )
protected

Acquire a new page from the heap. This is mostly used internally.

Returns
page structure of the newly acquired memory page.

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().

◆ pages()

unsigned ucommon::memalloc::pages ( void  ) const
inline

Get the number of pages that have been allocated from the real heap.

Returns
pages allocated from heap.

Definition at line 106 of file memory.h.

Referenced by ucommon::ObjectPager::pages(), ucommon::StringPager::pages(), and ucommon::DirPager::pages().

◆ purge()

void ucommon::memalloc::purge ( void  )

◆ size()

size_t ucommon::memalloc::size ( void  ) const
inline

◆ utilization()

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.

Returns
pager utilization.

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().

Friends And Related Function Documentation

◆ bufpager

friend class bufpager
friend

Definition at line 64 of file memory.h.

Member Data Documentation

◆ align

size_t ucommon::memalloc::align
private

Definition at line 66 of file memory.h.

Referenced by assign(), memalloc(), pager(), and purge().

◆ count

unsigned ucommon::memalloc::count
private

Definition at line 67 of file memory.h.

Referenced by assign(), memalloc(), pager(), and purge().

◆ limit

unsigned ucommon::memalloc::limit
protected

Definition at line 80 of file memory.h.

Referenced by assign(), memalloc(), and pager().

◆ page

page_t* ucommon::memalloc::page
private

Definition at line 77 of file memory.h.

Referenced by _alloc(), assign(), memalloc(), pager(), purge(), and utilization().

◆ pagesize

size_t ucommon::memalloc::pagesize
private

Definition at line 66 of file memory.h.

Referenced by _alloc(), assign(), memalloc(), pager(), and utilization().


The documentation for this class was generated from the following files: