From 8ea208daea207508b43b21a08e26b6135d8917a8 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 24 Nov 2015 16:48:46 +1100 Subject: [PATCH] alloc/linear: add capacity/size/remain implementations --- alloc/linear.cpp | 24 ++++++++++++++++++++++++ alloc/linear.hpp | 1 + 2 files changed, 25 insertions(+) diff --git a/alloc/linear.cpp b/alloc/linear.cpp index 8e1fdc41..80ed26a4 100644 --- a/alloc/linear.cpp +++ b/alloc/linear.cpp @@ -61,3 +61,27 @@ linear::reset (void) { m_cursor = m_begin; } + + +/////////////////////////////////////////////////////////////////////////////// +size_t +linear::capacity (void) const +{ + return m_end - m_begin; +} + + +//----------------------------------------------------------------------------- +size_t +linear::size (void) const +{ + return m_cursor - m_begin; +} + + +//----------------------------------------------------------------------------- +size_t +linear::remain (void) const +{ + return capacity () - size (); +} diff --git a/alloc/linear.hpp b/alloc/linear.hpp index 141c536e..303789b4 100644 --- a/alloc/linear.hpp +++ b/alloc/linear.hpp @@ -39,6 +39,7 @@ namespace util { namespace alloc { size_t capacity (void) const; size_t size (void) const; + size_t remain (void) const; protected: char *m_begin, *m_end, *m_cursor;