Move all header method implementations of SimpleMemoryAllocator to the cc file.
This is a cleanup to prepare for some recording and logging subclasses of this class to help TF Micro keep tracking of tail/head buffer allocations. PiperOrigin-RevId: 313247671 Change-Id: Id6766c02467e1829961addfcc449fdf6990ce684
This commit is contained in:
parent
741ef7999c
commit
c64cdf3098
|
@ -23,6 +23,20 @@ limitations under the License.
|
|||
|
||||
namespace tflite {
|
||||
|
||||
SimpleMemoryAllocator::SimpleMemoryAllocator(ErrorReporter* error_reporter,
|
||||
uint8_t* buffer_head,
|
||||
uint8_t* buffer_tail)
|
||||
: error_reporter_(error_reporter),
|
||||
buffer_head_(buffer_head),
|
||||
buffer_tail_(buffer_tail),
|
||||
head_(buffer_head),
|
||||
tail_(buffer_tail) {}
|
||||
|
||||
SimpleMemoryAllocator::SimpleMemoryAllocator(ErrorReporter* error_reporter,
|
||||
uint8_t* buffer,
|
||||
size_t buffer_size)
|
||||
: SimpleMemoryAllocator(error_reporter, buffer, buffer + buffer_size) {}
|
||||
|
||||
SimpleMemoryAllocator* CreateInPlaceSimpleMemoryAllocator(
|
||||
ErrorReporter* error_reporter, uint8_t* buffer, size_t buffer_size) {
|
||||
SimpleMemoryAllocator tmp =
|
||||
|
@ -64,4 +78,28 @@ uint8_t* SimpleMemoryAllocator::AllocateFromTail(size_t size,
|
|||
return aligned_result;
|
||||
}
|
||||
|
||||
uint8_t* SimpleMemoryAllocator::GetHead() const { return head_; }
|
||||
|
||||
uint8_t* SimpleMemoryAllocator::GetTail() const { return tail_; }
|
||||
|
||||
size_t SimpleMemoryAllocator::GetHeadUsedBytes() const {
|
||||
return head_ - buffer_head_;
|
||||
}
|
||||
|
||||
size_t SimpleMemoryAllocator::GetTailUsedBytes() const {
|
||||
return buffer_tail_ - tail_;
|
||||
}
|
||||
|
||||
size_t SimpleMemoryAllocator::GetAvailableMemory() const {
|
||||
return tail_ - head_;
|
||||
}
|
||||
|
||||
size_t SimpleMemoryAllocator::GetUsedBytes() const {
|
||||
return GetBufferSize() - GetAvailableMemory();
|
||||
}
|
||||
|
||||
size_t SimpleMemoryAllocator::GetBufferSize() const {
|
||||
return buffer_tail_ - buffer_head_;
|
||||
}
|
||||
|
||||
} // namespace tflite
|
||||
|
|
|
@ -29,15 +29,9 @@ namespace tflite {
|
|||
class SimpleMemoryAllocator {
|
||||
public:
|
||||
SimpleMemoryAllocator(ErrorReporter* error_reporter, uint8_t* buffer_head,
|
||||
uint8_t* buffer_tail)
|
||||
: error_reporter_(error_reporter),
|
||||
buffer_head_(buffer_head),
|
||||
buffer_tail_(buffer_tail),
|
||||
head_(buffer_head),
|
||||
tail_(buffer_tail) {}
|
||||
uint8_t* buffer_tail);
|
||||
SimpleMemoryAllocator(ErrorReporter* error_reporter, uint8_t* buffer,
|
||||
size_t buffer_size)
|
||||
: SimpleMemoryAllocator(error_reporter, buffer, buffer + buffer_size) {}
|
||||
size_t buffer_size);
|
||||
|
||||
// Allocates memory starting at the head of the arena (lowest address and
|
||||
// moving upwards).
|
||||
|
@ -46,16 +40,17 @@ class SimpleMemoryAllocator {
|
|||
// moving downwards).
|
||||
uint8_t* AllocateFromTail(size_t size, size_t alignment);
|
||||
|
||||
uint8_t* GetHead() const { return head_; }
|
||||
uint8_t* GetTail() const { return tail_; }
|
||||
size_t GetAvailableMemory() const { return tail_ - head_; }
|
||||
size_t GetUsedBytes() const { return GetBufferSize() - GetAvailableMemory(); }
|
||||
uint8_t* GetHead() const;
|
||||
uint8_t* GetTail() const;
|
||||
|
||||
size_t GetHeadUsedBytes() const { return head_ - buffer_head_; }
|
||||
size_t GetTailUsedBytes() const { return buffer_tail_ - tail_; }
|
||||
size_t GetHeadUsedBytes() const;
|
||||
size_t GetTailUsedBytes() const;
|
||||
|
||||
size_t GetAvailableMemory() const;
|
||||
size_t GetUsedBytes() const;
|
||||
|
||||
private:
|
||||
size_t GetBufferSize() const { return buffer_tail_ - buffer_head_; }
|
||||
size_t GetBufferSize() const;
|
||||
|
||||
ErrorReporter* error_reporter_;
|
||||
uint8_t* buffer_head_;
|
||||
|
|
Loading…
Reference in New Issue