FreeNOS
BubbleAllocator.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <Types.h>
19#include "BubbleAllocator.h"
20
22 : Allocator(range)
23 , m_allocated(0)
24{
25}
26
28{
29 return size() - m_allocated;
30}
31
33{
34 Size needed = aligned(args.size, alignment());
35
36 // Do we still have enough room?
37 if (m_allocated + needed <= size())
38 {
39 args.address = base() + m_allocated;
40 m_allocated += needed;
41 return Success;
42 }
43 // No more memory available
44 return OutOfMemory;
45}
46
48{
49 // BubbleAllocator never releases memory
50 return InvalidAddress;
51}
Memory Allocator.
Definition Allocator.h:47
Address base() const
Get memory base address for allocations.
Definition Allocator.cpp:69
virtual Size size() const
Get memory size.
Definition Allocator.cpp:64
Size alignment() const
Get memory alignment in bytes for allocations.
Definition Allocator.cpp:74
Result
Allocation results.
Definition Allocator.h:54
@ InvalidAddress
Definition Allocator.h:56
@ OutOfMemory
Definition Allocator.h:59
Address aligned(const Address addr, const Size boundary) const
Align memory address.
Definition Allocator.cpp:94
BubbleAllocator(const Range range)
Class constructor.
virtual Size available() const
Get memory available.
virtual Result release(const Address addr)
Release memory.
virtual Result allocate(Range &args)
Allocate memory.
Size m_allocated
Number of bytes allocated.
unsigned long Address
A memory address.
Definition Types.h:131
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Describes a range of memory.
Definition Allocator.h:66
Address address
Starting address of the memory range.
Definition Allocator.h:67
Size size
Amount of memory in bytes.
Definition Allocator.h:68