summaryrefslogtreecommitdiff
path: root/ace/Malloc_T.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1996-11-20 04:11:25 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1996-11-20 04:11:25 +0000
commit2e694cc1441a667d366395b889df4d30abe071c9 (patch)
tree0747106206d87c13e6e936a7846a68949abce9bf /ace/Malloc_T.cpp
parent6de6d532e993dc815715c1b0db5b77bb12fef96b (diff)
downloadATCD-2e694cc1441a667d366395b889df4d30abe071c9.tar.gz
*** empty log message ***
Diffstat (limited to 'ace/Malloc_T.cpp')
-rw-r--r--ace/Malloc_T.cpp26
1 files changed, 14 insertions, 12 deletions
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<ACE_MEM_POOL_2, LOCK>::find (const char *name, void *&pointer)
}
// Returns a count of the number of available chunks that can hold
-// <size> byte allocations.
+// <size> 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 <ACE_MEM_POOL_1, class LOCK> size_t
ACE_Malloc<ACE_MEM_POOL_2, LOCK>::avail_chunks (size_t size) const
{
- ACE_READ_GUARD_RETURN (LOCK, ace_mon, (LOCK &) this->lock_, 0);
+ ACE_TRACE ("ACE_Malloc<ACE_MEM_POOL_2, LOCK>::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;
}