BIND 10 trac2088, updated. 05a1e1a98e21ff9d5591af9c5debdbf74eb9cb77 [2088] Indent test code
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jul 6 06:06:59 UTC 2012
The branch, trac2088 has been updated
via 05a1e1a98e21ff9d5591af9c5debdbf74eb9cb77 (commit)
via 22690690bd3da8e82cdcaa38212317fc8d3d72fb (commit)
via a4296e2bbf266d31004f99569b8da028e84d8460 (commit)
from 00c9a91a3e5e83bc4255b8fbd31f15b6fcee09da (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 05a1e1a98e21ff9d5591af9c5debdbf74eb9cb77
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Jul 6 11:35:38 2012 +0530
[2088] Indent test code
commit 22690690bd3da8e82cdcaa38212317fc8d3d72fb
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Jul 6 11:33:01 2012 +0530
[2088] Rename test
commit a4296e2bbf266d31004f99569b8da028e84d8460
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Jul 6 11:00:34 2012 +0530
[2088] Document MemorySegment classes
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/memory_segment.h | 23 ++++++++++++
src/lib/util/memory_segment_local.h | 28 +++++++++++++++
.../util/tests/memory_segment_local_unittest.cc | 38 ++++++++++----------
3 files changed, 70 insertions(+), 19 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/util/memory_segment.h b/src/lib/util/memory_segment.h
index 6a06c3a..d1f4f4a 100644
--- a/src/lib/util/memory_segment.h
+++ b/src/lib/util/memory_segment.h
@@ -20,10 +20,33 @@
namespace isc {
namespace util {
+/// \brief Memory Segment Class
+///
+/// This class specifies an interface for allocating memory
+/// segments. This is an abstract class and a real
+/// implementation such as MemorySegmentLocal should be used
+/// in code.
class MemorySegment {
public:
+ /// \brief Allocate/acquire a segment of memory. The source of the
+ /// memory is dependent on the implementation used.
+ ///
+ /// \param size The size of the memory requested in bytes.
+ /// \return Returns pointer to the memory allocated.
virtual void* allocate(size_t size) = 0;
+
+ /// \brief Free/release a segment of memory.
+ ///
+ /// \param ptr Pointer to the block of memory to free/release. This
+ /// should be equal to a value returned by <code>allocate()</code>.
+ /// \param size The size of the memory to be freed in bytes. This
+ /// should be equal to the number of bytes originally allocated.
virtual void deallocate(void* ptr, size_t size) = 0;
+
+ /// \brief Check if all allocated memory was deallocated.
+ ///
+ /// \return Returns <code>true</code> if all allocated memory was
+ /// deallocated, <code>false</code> otherwise.
virtual bool allMemoryDeallocated() const = 0;
};
diff --git a/src/lib/util/memory_segment_local.h b/src/lib/util/memory_segment_local.h
index cc7929c..87be0fc 100644
--- a/src/lib/util/memory_segment_local.h
+++ b/src/lib/util/memory_segment_local.h
@@ -20,16 +20,44 @@
namespace isc {
namespace util {
+/// \brief malloc/free based Memory Segment class
+///
+/// This class specifies a concrete implementation for a malloc/free
+/// based MemorySegment. Please see the MemorySegment class
+/// documentation for usage.
class MemorySegmentLocal : public MemorySegment {
public:
+ /// \brief Constructor
+ ///
+ /// Creates a local memory segment object
MemorySegmentLocal() : allocated_size_(0) {
}
+ /// \brief Allocate/acquire a segment of memory. The source of the
+ /// memory is libc's malloc().
+ ///
+ /// \param size The size of the memory requested in bytes.
+ /// \return Returns pointer to the memory allocated.
void* allocate(size_t size);
+
+ /// \brief Free/release a segment of memory.
+ ///
+ /// \param ptr Pointer to the block of memory to free/release. This
+ /// should be equal to a value returned by <code>allocate()</code>.
+ /// \param size The size of the memory to be freed in bytes. This
+ /// should be equal to the number of bytes originally allocated.
void deallocate(void* ptr, size_t size);
+
+ /// \brief Check if all allocated memory was deallocated.
+ ///
+ /// \return Returns <code>true</code> if all allocated memory was
+ /// deallocated, <code>false</code> otherwise.
bool allMemoryDeallocated() const;
private:
+ // allocated_size_ can underflow, wrap around to max size_t (which
+ // is unsigned). But because we only do a check against 0 and not a
+ // relation comparison, this is okay.
size_t allocated_size_;
};
diff --git a/src/lib/util/tests/memory_segment_local_unittest.cc b/src/lib/util/tests/memory_segment_local_unittest.cc
index f0da842..95736cf 100644
--- a/src/lib/util/tests/memory_segment_local_unittest.cc
+++ b/src/lib/util/tests/memory_segment_local_unittest.cc
@@ -21,35 +21,35 @@ using namespace std;
namespace isc {
namespace util {
-TEST(MemorySegmentLocal, testDefault) {
- auto_ptr<MemorySegment> segment(new MemorySegmentLocal());
+TEST(MemorySegmentLocal, TestLocal) {
+ auto_ptr<MemorySegment> segment(new MemorySegmentLocal());
- // By default, nothing is allocated.
- EXPECT_TRUE(segment->allMemoryDeallocated());
+ // By default, nothing is allocated.
+ EXPECT_TRUE(segment->allMemoryDeallocated());
- void *ptr = segment->allocate(1024);
+ void *ptr = segment->allocate(1024);
- // Now, we have an allocation:
- EXPECT_FALSE(segment->allMemoryDeallocated());
+ // Now, we have an allocation:
+ EXPECT_FALSE(segment->allMemoryDeallocated());
- void *ptr2 = segment->allocate(42);
+ void *ptr2 = segment->allocate(42);
- // Still:
- EXPECT_FALSE(segment->allMemoryDeallocated());
+ // Still:
+ EXPECT_FALSE(segment->allMemoryDeallocated());
- // These should not fail, because the buffers have been allocated.
- EXPECT_NO_FATAL_FAILURE(memset(ptr, 0, 1024));
- EXPECT_NO_FATAL_FAILURE(memset(ptr, 0, 42));
+ // These should not fail, because the buffers have been allocated.
+ EXPECT_NO_FATAL_FAILURE(memset(ptr, 0, 1024));
+ EXPECT_NO_FATAL_FAILURE(memset(ptr, 0, 42));
- segment->deallocate(ptr, 1024);
+ segment->deallocate(ptr, 1024);
- // Still:
- EXPECT_FALSE(segment->allMemoryDeallocated());
+ // Still:
+ EXPECT_FALSE(segment->allMemoryDeallocated());
- segment->deallocate(ptr2, 42);
+ segment->deallocate(ptr2, 42);
- // Now, we have an deallocated everything:
- EXPECT_TRUE(segment->allMemoryDeallocated());
+ // Now, we have an deallocated everything:
+ EXPECT_TRUE(segment->allMemoryDeallocated());
}
} // namespace util
More information about the bind10-changes
mailing list