Daniele Bartolini 10 年之前
父節點
當前提交
9fb20ee57d
共有 2 個文件被更改,包括 11 次插入6 次删除
  1. 6 3
      src/core/memory/linear_allocator.cpp
  2. 5 3
      src/core/memory/linear_allocator.h

+ 6 - 3
src/core/memory/linear_allocator.cpp

@@ -31,18 +31,21 @@ LinearAllocator::~LinearAllocator()
 	if (_backing)
 		_backing->deallocate(_physical_start);
 
-	CE_ASSERT(_offset == 0, "Memory leak of %d bytes, maybe you forgot to call clear()?", _offset);
+	CE_ASSERT(_offset == 0
+		, "Memory leak of %d bytes, maybe you forgot to call clear()?"
+		, _offset
+		);
 }
 
 void* LinearAllocator::allocate(uint32_t size, uint32_t align)
 {
 	const uint32_t actual_size = size + align;
 
-	// Memory exhausted
+	// Out of memory
 	if (_offset + actual_size > _total_size)
 		return NULL;
 
-	void* user_ptr = memory::align_top((char*) _physical_start + _offset, align);
+	void* user_ptr = memory::align_top((char*)_physical_start + _offset, align);
 
 	_offset += actual_size;
 

+ 5 - 3
src/core/memory/linear_allocator.h

@@ -10,15 +10,18 @@
 namespace crown
 {
 
-/// Allocates memory linearly from a predefined chunk
-/// and frees all the allocations with a single call to clear()
+/// Allocates memory linearly from a fixed chunk of memory
+/// and frees all the allocations with a single call to clear().
 ///
 /// @ingroup Memory
 class LinearAllocator : public Allocator
 {
 public:
 
+	/// Allocates @a size bytes from @a backing.
 	LinearAllocator(Allocator& backing, uint32_t size);
+
+	/// Uses @a size bytes of memory from @a start.
 	LinearAllocator(void* start, uint32_t size);
 	~LinearAllocator();
 
@@ -44,7 +47,6 @@ public:
 private:
 
 	Allocator* _backing;
-
 	void* _physical_start;
 	uint32_t _total_size;
 	uint32_t _offset;