ACE_Static_Allocator_Base Class Reference

Defines a class that provided a highly optimized memory management scheme for allocating memory statically. More...

#include <Malloc_Allocator.h>

Inheritance diagram for ACE_Static_Allocator_Base:

Inheritance graph
[legend]
Collaboration diagram for ACE_Static_Allocator_Base:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Static_Allocator_Base (char *buffer, size_t size)
virtual void * malloc (size_t nbytes)
 Allocate , but don't give them any initial value.

virtual void * calloc (size_t nbytes, char initial_value= '\0')
 Allocate , giving them .

virtual void * calloc (size_t n_elem, size_t elem_size, char initial_value= '\0')
virtual void free (void *ptr)
 Free (must have been allocated by <ACE_Allocator::malloc>).

virtual int remove (void)
 Remove any resources associated with this memory manager.

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)
 Returns 0 if the name is in the mapping. -1, otherwise.

virtual int unbind (const char *name)
virtual int unbind (const char *name, void *&pointer)
virtual int sync (ssize_t len=-1, int flags=MS_SYNC)
virtual int sync (void *addr, size_t len, int flags=MS_SYNC)
virtual int protect (ssize_t len=-1, int prot=PROT_RDWR)
virtual int protect (void *addr, size_t len, int prot=PROT_RDWR)
virtual void dump (void) const
 Dump the state of the object.


Protected Member Functions

 ACE_Static_Allocator_Base (void)
 Don't allow direct instantiations of this class.


Protected Attributes

char * buffer_
 Pointer to the buffer.

size_t size_
 Size of the buffer.

size_t offset_
 Pointer to the current offset in the .


Detailed Description

Defines a class that provided a highly optimized memory management scheme for allocating memory statically.

This class manages a fixed-size of memory. Every time / is called, it simply moves an internal index forward and returns a pointer to the requested chunk. All memory is allocated statically (typically via the ACE_Static_Allocator template) and is a no-op. This behavior is useful for use-cases where all the memory allocation needs are known in advance and no deletions ever occur.

Definition at line 100 of file Malloc_Allocator.h.


Constructor & Destructor Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_Static_Allocator_Base::ACE_Static_Allocator_Base char *  buffer,
size_t  size
 

Definition at line 8 of file Malloc_Allocator.inl.

00010   : buffer_ (buffer),
00011     size_ (size),
00012     offset_ (0)
00013 {
00014 }

ACE_Static_Allocator_Base::ACE_Static_Allocator_Base void   )  [protected]
 

Don't allow direct instantiations of this class.


Member Function Documentation

int ACE_Static_Allocator_Base::bind const char *  name,
void *  pointer,
int  duplicates = 0
[virtual]
 

Associate with . If == 0 then do not allow duplicate / associations, else if != 0 then allow duplicate / assocations. Returns 0 if successfully binds (1) a previously unbound or (2) != 0, returns 1 if trying to bind a previously bound and == 0, else returns -1 if a resource failure occurs.

Implements ACE_Allocator.

Definition at line 279 of file Malloc_Allocator.cpp.

00280 {
00281   return -1;
00282 }

void * ACE_Static_Allocator_Base::calloc size_t  n_elem,
size_t  elem_size,
char  initial_value = '\0'
[virtual]
 

Allocate each of size , giving them .

Implements ACE_Allocator.

Definition at line 257 of file Malloc_Allocator.cpp.

References calloc().

00260 {
00261   return this->calloc (n_elem * elem_size, initial_value);
00262 }

void * ACE_Static_Allocator_Base::calloc size_t  nbytes,
char  initial_value = '\0'
[virtual]
 

Allocate , giving them .

Implements ACE_Allocator.

Definition at line 247 of file Malloc_Allocator.cpp.

References malloc(), and ACE_OS::memset().

Referenced by calloc().

00249 {
00250   void *ptr = this->malloc (nbytes);
00251 
00252   ACE_OS::memset (ptr, initial_value, nbytes);
00253   return (void *) ptr;
00254 }

void ACE_Static_Allocator_Base::dump void   )  const [virtual]
 

Dump the state of the object.

Implements ACE_Allocator.

Definition at line 346 of file Malloc_Allocator.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_HEX_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00347 {
00348 #if defined (ACE_HAS_DUMP)
00349   ACE_TRACE ("ACE_Static_Allocator_Base::dump");
00350 
00351   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00352   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\noffset_ = %d"), this->offset_));
00353   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nsize_ = %d\n"), this->size_));
00354   ACE_HEX_DUMP ((LM_DEBUG, this->buffer_, this->size_));
00355   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00356 
00357   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00358 #endif /* ACE_HAS_DUMP */
00359 }

int ACE_Static_Allocator_Base::find const char *  name  )  [virtual]
 

Returns 0 if the name is in the mapping. -1, otherwise.

Implements ACE_Allocator.

Definition at line 297 of file Malloc_Allocator.cpp.

00298 {
00299   return -1;
00300 }

int ACE_Static_Allocator_Base::find const char *  name,
void *&  pointer
[virtual]
 

Locate and pass out parameter via pointer. If found, return 0, returns -1 if failure occurs.

Implements ACE_Allocator.

Definition at line 291 of file Malloc_Allocator.cpp.

00292 {
00293   return -1;
00294 }

void ACE_Static_Allocator_Base::free void *  ptr  )  [virtual]
 

Free (must have been allocated by <ACE_Allocator::malloc>).

Implements ACE_Allocator.

Definition at line 265 of file Malloc_Allocator.cpp.

References ACE_ASSERT, and buffer_.

00266 {
00267   // Check to see if ptr is within our pool?!
00268   ACE_UNUSED_ARG (ptr);
00269   ACE_ASSERT (ptr >= this->buffer_ && ptr < this->buffer_ + this->size_);
00270 }

void * ACE_Static_Allocator_Base::malloc size_t  nbytes  )  [virtual]
 

Allocate , but don't give them any initial value.

Implements ACE_Allocator.

Definition at line 229 of file Malloc_Allocator.cpp.

References buffer_, and offset_.

Referenced by calloc().

00230 {
00231   if (this->offset_ + nbytes > this->size_)
00232     {
00233       errno = ENOMEM;
00234       return 0;
00235     }
00236   else
00237     {
00238       // Record the current offset, increment the offset by the number
00239       // of bytes requested, and return the original offset.
00240       char *ptr = &this->buffer_[this->offset_];
00241       this->offset_ += nbytes;
00242       return (void *) ptr;
00243     }
00244 }

int ACE_Static_Allocator_Base::protect void *  addr,
size_t  len,
int  prot = PROT_RDWR
[virtual]
 

Change the protection of the pages of the mapped region to starting at up to bytes.

Implements ACE_Allocator.

Definition at line 333 of file Malloc_Allocator.cpp.

00334 {
00335   return -1;
00336 }

int ACE_Static_Allocator_Base::protect ssize_t  len = -1,
int  prot = PROT_RDWR
[virtual]
 

Change the protection of the pages of the mapped region to starting at <this->base_addr_> up to bytes. If == -1 then change protection of all pages in the mapped region.

Implements ACE_Allocator.

Definition at line 327 of file Malloc_Allocator.cpp.

References ssize_t.

00328 {
00329   return -1;
00330 }

int ACE_Static_Allocator_Base::remove void   )  [virtual]
 

Remove any resources associated with this memory manager.

Implements ACE_Allocator.

Definition at line 273 of file Malloc_Allocator.cpp.

00274 {
00275   return -1;
00276 }

int ACE_Static_Allocator_Base::sync void *  addr,
size_t  len,
int  flags = MS_SYNC
[virtual]
 

Sync len bytes of the memory region to the backing store starting at addr.

Implements ACE_Allocator.

Definition at line 321 of file Malloc_Allocator.cpp.

00322 {
00323   return -1;
00324 }

int ACE_Static_Allocator_Base::sync ssize_t  len = -1,
int  flags = MS_SYNC
[virtual]
 

Sync len bytes of the memory region to the backing store starting at this->base_addr_. If len == -1 then sync the whole region.

Implements ACE_Allocator.

Definition at line 315 of file Malloc_Allocator.cpp.

References ssize_t.

00316 {
00317   return -1;
00318 }

int ACE_Static_Allocator_Base::trybind const char *  name,
void *&  pointer
[virtual]
 

Associate with . Does not allow duplicate / associations. Returns 0 if successfully binds (1) a previously unbound , 1 if trying to bind a previously bound , or returns -1 if a resource failure occurs. When this call returns 's value will always reference the void * that is associated with. Thus, if the caller needs to use (e.g., to free it) a copy must be maintained by the caller.

Implements ACE_Allocator.

Definition at line 285 of file Malloc_Allocator.cpp.

00286 {
00287   return -1;
00288 }

int ACE_Static_Allocator_Base::unbind const char *  name,
void *&  pointer
[virtual]
 

Break any association of name. Returns the value of pointer in case the caller needs to deallocate memory.

Implements ACE_Allocator.

Definition at line 309 of file Malloc_Allocator.cpp.

00310 {
00311   return -1;
00312 }

int ACE_Static_Allocator_Base::unbind const char *  name  )  [virtual]
 

Unbind (remove) the name from the map. Don't return the pointer to the caller

Implements ACE_Allocator.

Definition at line 303 of file Malloc_Allocator.cpp.

00304 {
00305   return -1;
00306 }


Member Data Documentation

char* ACE_Static_Allocator_Base::buffer_ [protected]
 

Pointer to the buffer.

Definition at line 129 of file Malloc_Allocator.h.

Referenced by free(), and malloc().

size_t ACE_Static_Allocator_Base::offset_ [protected]
 

Pointer to the current offset in the .

Definition at line 135 of file Malloc_Allocator.h.

Referenced by malloc().

size_t ACE_Static_Allocator_Base::size_ [protected]
 

Size of the buffer.

Definition at line 132 of file Malloc_Allocator.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:30:08 2006 for ACE by doxygen 1.3.6