diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 2001-04-13 12:26:02 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 2001-04-13 12:26:02 +0000 |
commit | 9560ce25f1faa97709827d78c1314c2c6c5acde1 (patch) | |
tree | 66e0c8f786c7ac33181de7e24bd8d9bcf2c97b6a /ace | |
parent | 15521b4ca7fec6a65aa6939e254e43f7b1386859 (diff) | |
download | ATCD-9560ce25f1faa97709827d78c1314c2c6c5acde1.tar.gz |
ChangeLogTag:Fri Apr 13 05:30:04 2001 Douglas C. Schmidt <schmidt@tango.doc.wustl.edu>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Malloc.h | 1 | ||||
-rw-r--r-- | ace/Malloc_Allocator.h | 22 | ||||
-rw-r--r-- | ace/Malloc_Allocator.i | 22 | ||||
-rw-r--r-- | ace/Malloc_T.h | 21 | ||||
-rw-r--r-- | ace/Malloc_T.i | 23 | ||||
-rw-r--r-- | ace/Reactor.h | 1 |
6 files changed, 65 insertions, 25 deletions
diff --git a/ace/Malloc.h b/ace/Malloc.h index deec257078d..f36c60661e0 100644 --- a/ace/Malloc.h +++ b/ace/Malloc.h @@ -10,7 +10,6 @@ */ //============================================================================= - #ifndef ACE_MALLOC_H #define ACE_MALLOC_H #include "ace/pre.h" diff --git a/ace/Malloc_Allocator.h b/ace/Malloc_Allocator.h index ad848c2966a..b932adb74f4 100644 --- a/ace/Malloc_Allocator.h +++ b/ace/Malloc_Allocator.h @@ -1,15 +1,15 @@ +/* -*- C++ -*- */ //============================================================================= /** * @file Malloc_Allocator.h * * $Id$ - * + * * @author Priyanka Gontla <pgontla@ece.uci.edu> */ //============================================================================= - #ifndef MALLOC_ALLOCATOR_H #define MALLOC_ALLOCATOR_H #include "ace/pre.h" @@ -60,21 +60,25 @@ struct ACE_Export ACE_Malloc_Stats * @brief Defines a class that provided a simple implementation of * memory allocation. * - * This class uses the new/delete operators to allocate and free - * up memory. Please note that the only methods that are - * supported are malloc and free. All other methods are no-ops. - * If you require this functionality, please use: - * ACE_Allocator_Adapter <ACE_Malloc <ACE_LOCAL_MEMORY_POOL, - * MUTEX> > This will allow you to use the added functionality - * of bind/find/etc. while using the new/delete operators. + * This class uses the new/delete operators to allocate and free up + * memory. Please note that the only methods that are supported are + * <malloc>, <calloc>, and <free>. All other methods are no-ops that + * return -1 and set <errno> to <ENOTSUP>. If you require this + * functionality, please use: ACE_Allocator_Adapter <ACE_Malloc + * <ACE_LOCAL_MEMORY_POOL, MUTEX> >, which will allow you to use the + * added functionality of bind/find/etc. while using the new/delete + * operators. */ class ACE_Export ACE_New_Allocator : public ACE_Allocator { 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); diff --git a/ace/Malloc_Allocator.i b/ace/Malloc_Allocator.i index 045f4aec13b..b0cfd89b218 100644 --- a/ace/Malloc_Allocator.i +++ b/ace/Malloc_Allocator.i @@ -37,67 +37,67 @@ ACE_New_Allocator::free (void *ptr) ACE_INLINE int ACE_New_Allocator::remove (void) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::bind (const char *, void *, int) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::trybind (const char *, void *&) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::find (const char *, void *&) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::find (const char *) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::unbind (const char *) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::unbind (const char *, void *&) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::sync (ssize_t, int) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::sync (void *, size_t, int) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::protect (ssize_t, int) { - return -1; + ACE_NOTSUP_RETURN (-1); } ACE_INLINE int ACE_New_Allocator::protect (void *, size_t, int) { - return -1; + ACE_NOTSUP_RETURN (-1); } #if defined (ACE_HAS_MALLOC_STATS) diff --git a/ace/Malloc_T.h b/ace/Malloc_T.h index cb208f0ad16..5364a4d7acb 100644 --- a/ace/Malloc_T.h +++ b/ace/Malloc_T.h @@ -84,18 +84,33 @@ public: ~ACE_Cached_Allocator (void); /** - * Get a chunk of memory from free store. Note that <nbytes> is + * Get a chunk of memory from free list cache. Note that <nbytes> is * only checked to make sure that it's <= to sizeof T, and is * otherwise ignored since <malloc> always returns a pointer to an * item of sizeof (T). */ void *malloc (size_t nbytes = sizeof (T)); - /// return a chunk of memory back to free store. + /** + * Get a chunk of memory from free list cache, giving them + * <initial_value>. Note that <nbytes> is only checked to make sure + * that it's <= to sizeof T, and is otherwise ignored since <malloc> + * always returns a pointer to an item of sizeof (T). + */ + virtual void *calloc (size_t nbytes, + char initial_value = '\0'); + + /// This method is a no-op and just returns 0 since the free list + /// only works with fixed sized entities. + virtual void *calloc (size_t n_elem, + size_t elem_size, + char initial_value = '\0'); + + /// Return a chunk of memory back to free list cache. void free (void *); private: - /// remember how we allocate the memory in the first place so + /// Remember how we allocate the memory in the first place so /// we can clear things up later. char *pool_; diff --git a/ace/Malloc_T.i b/ace/Malloc_T.i index 28c943ba08b..dbe502de44b 100644 --- a/ace/Malloc_T.i +++ b/ace/Malloc_T.i @@ -36,6 +36,29 @@ ACE_Cached_Allocator<T, ACE_LOCK>::malloc (size_t nbytes) return this->free_list_.remove ()->addr (); } +template <class T, class ACE_LOCK> ACE_INLINE void * +ACE_Cached_Allocator<T, ACE_LOCK>::calloc (size_t nbytes, + char initial_value) +{ + // Check if size requested fits within pre-determined size. + if (nbytes > sizeof (T)) + return NULL; + + // addr() call is really not absolutely necessary because of the way + // ACE_Cached_Mem_Pool_Node's internal structure arranged. + void *ptr = this->free_list_.remove ()->addr (); + ACE_OS::memset (ptr, initial_value, sizeof (T)); + return ptr; +} + +template <class T, class ACE_LOCK> ACE_INLINE void * +ACE_Cached_Allocator<T, ACE_LOCK>::calloc (size_t, + size_t, + char) +{ + ACE_NOTSUP_RETURN (0); +} + template <class T, class ACE_LOCK> ACE_INLINE void ACE_Cached_Allocator<T, ACE_LOCK>::free (void * ptr) { diff --git a/ace/Reactor.h b/ace/Reactor.h index a80c98b6289..038f5eef7bb 100644 --- a/ace/Reactor.h +++ b/ace/Reactor.h @@ -10,7 +10,6 @@ */ //============================================================================= - #ifndef ACE_REACTOR_H #define ACE_REACTOR_H #include "ace/pre.h" |