]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2088] Document MemorySegment classes
authorMukund Sivaraman <muks@isc.org>
Fri, 6 Jul 2012 05:30:34 +0000 (11:00 +0530)
committerMukund Sivaraman <muks@isc.org>
Fri, 6 Jul 2012 06:02:14 +0000 (11:32 +0530)
src/lib/util/memory_segment.h
src/lib/util/memory_segment_local.h

index 6a06c3abf27a56ad6684a7fb6adc0271e11a0446..d1f4f4a6b0cdca51267f3a6542058d863eeb0b69 100644 (file)
 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;
 };
 
index cc7929cd5cd7efb5b5274bb84843ee27b058467b..87be0fc6707bf2f43faf949bd59b2e825300989f 100644 (file)
 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_;
 };