From 2e694cc1441a667d366395b889df4d30abe071c9 Mon Sep 17 00:00:00 2001 From: schmidt Date: Wed, 20 Nov 1996 04:11:25 +0000 Subject: *** empty log message *** --- ace/Malloc_T.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'ace/Malloc_T.cpp') diff --git a/ace/Malloc_T.cpp b/ace/Malloc_T.cpp index d3f3ebe3313..ee524474e9f 100644 --- a/ace/Malloc_T.cpp +++ b/ace/Malloc_T.cpp @@ -454,29 +454,31 @@ ACE_Malloc::find (const char *name, void *&pointer) } // Returns a count of the number of available chunks that can hold -// byte allocations. +// byte allocations. Function can be used to determine if you +// have reached a water mark. This implies a fixed amount of allocated +// memory. +// +// @param size - the chunk size of that you would like a count of +// @return function returns the number of chunks of the given size +// that would fit in the currently allocated memory template size_t ACE_Malloc::avail_chunks (size_t size) const { - ACE_READ_GUARD_RETURN (LOCK, ace_mon, (LOCK &) this->lock_, 0); + ACE_TRACE ("ACE_Malloc::avail_chunks"); + + ACE_READ_GUARD_RETURN (LOCK, ace_mon, (LOCK &) this->lock_, -1); size_t count = 0; // Avoid dividing by 0... size = size == 0 ? 1 : size; - const size_t sizeof_oversize = sizeof (ACE_Malloc_Header) / size; for (ACE_Malloc_Header *currp = this->cb_ptr_->freep_->s_.next_block_; - ; + currp != this->cb_ptr_->freep_; currp = currp->s_.next_block_) - { - if (currp->s_.size_ * sizeof (ACE_Malloc_Header) >= sizeof_oversize) - // How many will fit in this block. - count += currp->s_.size_ * sizeof_oversize; - - if (currp == this->cb_ptr_->freep_) - break; - } + // calculate how many will fit in this block. + if (currp->s_.size_ * sizeof (ACE_Malloc_Header) >= size) + count += currp->s_.size_ * sizeof (ACE_Malloc_Header) / size; return count; } -- cgit v1.2.1