Code size analysis#

pw_allocator: Flexible, safe, and measurable memory allocation

This module provides the Allocator interface, as well as several implementations of it. The tables below shows the relative code size for the interface and each of these implementations. The measurement includes a call to each method.

Allocator interface#

The following shows the code size incurred by the Allocator interface itself. A call to each method of the interface is measured using an empty implementation, NullAllocator.

Label

Segment

Delta

NullAllocator

FLASH

-8

[section .code]

-4

quorem

+4

pw::Allocator::DoResize()

+166

main

NEW

+60

pw::allocator::GetNullAllocator()

NEW

+56

pw::allocator::NullAllocator

NEW

+38

pw::Allocator::Allocate()

NEW

+38

pw::Allocator::New<>()

NEW

+20

pw::allocator::NullAllocator::DoDeallocate()

NEW

+18

pw::allocator::NullAllocator::~NullAllocator()

NEW

+14

pw::allocator::NullAllocator::DoAllocate()

NEW

+12

pw::allocator::internal::BaseUniquePtr::HasCapability()

NEW

+10

pw::Deallocator::Deallocate()

NEW

+10

pw::allocator::internal::BaseUniquePtr::Deallocate()

NEW

+6

pw::Deallocator::DoGetInfo()

+440

Concrete allocator implementations#

The following are code sizes for each of the provided allocator implementations that directly manage the memory they use to fulfill requests. These are measured relative to the empty implementation measured above.

Label

Segment

Delta

BestFitBlockAllocator

FLASH

+4

quorem

+212

pw::allocator::Block<>::Resize()

+118

main

+158

pw::allocator::BlockAllocator<>::DoGetInfo()

+148

pw::allocator::BlockAllocator<>::DoDeallocate()

+128

pw::allocator::Block<>::CanAllocLast()

+114

pw::allocator::BlockAllocator<>::DoResize()

+116

pw::allocator::Block<>::Split()

+88

pw::allocator::Block<>::MergeNext()

+90

pw::allocator::Block<>::Free()

+88

pw::allocator::Block<>::CrashIfInvalid()

+72

pw::allocator::BlockAllocator<>::Init()

+64

pw::allocator::BlockAllocator<>

-8

pw::allocator::NullAllocator

+46

pw::allocator::BlockAllocator<>::FromUsableSpace<>()

+40

pw::allocator::BlockAllocator<>::DoAllocate()

+2

pw::allocator::BucketBlockAllocator<>::ReserveBlock()

+30

pw::allocator::BlockAllocator<>::NextIsFree()

+28

pw::allocator::BlockAllocator<>::UpdateLast()

-2

pw_boot_PreStaticMemoryInit

+2

pw::allocator::Block<>::Iterator::operator++()

+16

pw::allocator::Block<>::Next()

+14

pw::allocator::Block<>::Prev()

+2

pw::allocator::internal::Bucket::Bucket()

+16

pw::Deallocator::DoGetInfo()

+8

pw::allocator::internal::GenericBlockAllocator::kCapabilities

+2

pw::allocator::BlockAllocator<>::RecycleBlock()

+2

pw::allocator::BlockAllocator<>::ReserveBlock()

NEW

+210

pw::allocator::BestFitBlockAllocator<>::ChooseBlock()

NEW

+64

pw::allocator::BestFitBlockAllocator<>

NEW

+64

pw::allocator::BestFitBlockAllocator<>::~BestFitBlockAllocator()

+1,936

BuddyAllocator

FLASH

+240

[section .code]

+54

main

-8

pw::allocator::NullAllocator

+2

pw::allocator::BucketBlockAllocator<>::ReserveBlock()

+20

fit::internal::target<>::invoke()

+40

fit::internal::target<>::ops

+16

pw::allocator::internal::Bucket::Remove()

+2

pw::allocator::internal::Bucket::Bucket()

+2

pw::allocator::internal::BaseUniquePtr::Deallocate()

NEW

+220

pw::allocator::internal::GenericBuddyAllocator::Deallocate()

NEW

+148

pw::allocator::internal::GenericBuddyAllocator::Allocate()

NEW

+116

pw::allocator::internal::GenericBuddyAllocator::Init()

NEW

+112

pw::allocator::internal::GenericBuddyAllocator::CrashIfAllocated()

NEW

+110

pw::allocator::BuddyAllocator<>::DoGetInfo()

NEW

+80

pw::allocator::internal::GenericBuddyAllocator::GetLayout()

NEW

+68

CSWTCH.1

NEW

+52

pw::allocator::BuddyAllocator<>

NEW

+44

pw::allocator::BuddyAllocator<>::~BuddyAllocator()

NEW

+40

pw::allocator::BuddyAllocator<>::DoAllocate()

NEW

+40

pw::allocator::internal::Bucket::count()

NEW

+36

pw::allocator::internal::GenericBuddyAllocator::GenericBuddyAllocator()

NEW

+28

pw::allocator::internal::Bucket::Visit()

NEW

+24

pw_StatusString

NEW

+18

pw::Deallocator::DoDeallocate()

NEW

+8

pw::allocator::BuddyAllocator<>::DoDeallocate()

+1,512

BumpAllocator

FLASH

+34

main

-8

pw::allocator::NullAllocator

+2

pw::Allocator::New<>()

+4

p05.0

NEW

+56

pw::allocator::BumpAllocator

NEW

+50

pw::allocator::BumpAllocator::DoAllocate()

NEW

+40

pw::allocator::BumpAllocator::~BumpAllocator()

NEW

+32

pw::allocator::BumpAllocator::Init()

NEW

+22

pw::allocator::BumpAllocator::Reset()

NEW

+18

pw::Deallocator::DoDeallocate()

NEW

+4

pw::allocator::BumpAllocator::kCapabilities

NEW

+2

pw::allocator::BumpAllocator::DoDeallocate()

+256

DualFirstFitBlockAllocator

FLASH

+4

quorem

+216

pw::allocator::Block<>::Resize()

+122

main

+158

pw::allocator::BlockAllocator<>::DoGetInfo()

+148

pw::allocator::BlockAllocator<>::DoDeallocate()

+114

pw::allocator::BlockAllocator<>::DoResize()

+116

pw::allocator::Block<>::Split()

+88

pw::allocator::Block<>::MergeNext()

+90

pw::allocator::Block<>::Free()

+88

pw::allocator::Block<>::CrashIfInvalid()

+76

pw::allocator::BlockAllocator<>::Init()

+64

pw::allocator::BlockAllocator<>

-8

pw::allocator::NullAllocator

+46

pw::allocator::BlockAllocator<>::FromUsableSpace<>()

+40

pw::allocator::BlockAllocator<>::DoAllocate()

+2

pw::allocator::BucketBlockAllocator<>::ReserveBlock()

+28

pw::allocator::BlockAllocator<>::NextIsFree()

+28

pw::allocator::BlockAllocator<>::UpdateLast()

+20

pw::allocator::Block<>::Iterator::operator++()

+16

pw::allocator::Block<>::Next()

+14

pw::allocator::Block<>::Prev()

+2

pw::allocator::internal::Bucket::Bucket()

+16

pw::Deallocator::DoGetInfo()

+8

pw::allocator::internal::GenericBlockAllocator::kCapabilities

+2

pw::allocator::BlockAllocator<>::RecycleBlock()

+2

pw::allocator::BlockAllocator<>::ReserveBlock()

NEW

+238

pw::allocator::DualFirstFitBlockAllocator<>::ChooseBlock()

NEW

+216

pw::allocator::Block<>::AllocFirst()

NEW

+86

pw::allocator::Block<>::ShiftBlock()

NEW

+64

pw::allocator::DualFirstFitBlockAllocator<>

NEW

+64

pw::allocator::DualFirstFitBlockAllocator<>::~DualFirstFitBlockAllocator()

NEW

+24

pw::AlignUp()

+2,192

FirstFitBlockAllocator

FLASH

+4

quorem

+216

pw::allocator::Block<>::Resize()

+118

main

+158

pw::allocator::BlockAllocator<>::DoGetInfo()

+148

pw::allocator::BlockAllocator<>::DoDeallocate()

+114

pw::allocator::BlockAllocator<>::DoResize()

+116

pw::allocator::Block<>::Split()

+88

pw::allocator::Block<>::MergeNext()

+90

pw::allocator::Block<>::Free()

+88

pw::allocator::Block<>::CrashIfInvalid()

+76

pw::allocator::BlockAllocator<>::Init()

+64

pw::allocator::BlockAllocator<>

-8

pw::allocator::NullAllocator

+46

pw::allocator::BlockAllocator<>::FromUsableSpace<>()

+40

pw::allocator::BlockAllocator<>::DoAllocate()

+2

pw::allocator::BucketBlockAllocator<>::ReserveBlock()

+28

pw::allocator::BlockAllocator<>::NextIsFree()

+28

pw::allocator::BlockAllocator<>::UpdateLast()

-2

pw_boot_PreStaticMemoryInit

+20

pw::allocator::Block<>::Iterator::operator++()

+16

pw::allocator::Block<>::Next()

+14

pw::allocator::Block<>::Prev()

+2

pw::allocator::internal::Bucket::Bucket()

+16

pw::Deallocator::DoGetInfo()

+8

pw::allocator::internal::GenericBlockAllocator::kCapabilities

+2

pw::allocator::BlockAllocator<>::RecycleBlock()

+2

pw::allocator::BlockAllocator<>::ReserveBlock()

NEW

+350

pw::allocator::Block<>::AllocFirst()

NEW

+64

pw::allocator::FirstFitBlockAllocator<>

NEW

+64

pw::allocator::FirstFitBlockAllocator<>::~FirstFitBlockAllocator()

NEW

+52

pw::allocator::FirstFitBlockAllocator<>::ChooseBlock()

NEW

+24

pw::AlignUp()

+2,048

LastFitBlockAllocator

FLASH

+212

pw::allocator::Block<>::Resize()

+118

main

+158

pw::allocator::BlockAllocator<>::DoGetInfo()

+148

pw::allocator::BlockAllocator<>::DoDeallocate()

+114

pw::allocator::BlockAllocator<>::DoResize()

+116

pw::allocator::Block<>::Split()

+88

pw::allocator::Block<>::MergeNext()

+90

pw::allocator::Block<>::Free()

+88

pw::allocator::Block<>::CrashIfInvalid()

+72

pw::allocator::BlockAllocator<>::Init()

+64

pw::allocator::BlockAllocator<>

-8

pw::allocator::NullAllocator

+46

pw::allocator::BlockAllocator<>::FromUsableSpace<>()

+40

pw::allocator::BlockAllocator<>::DoAllocate()

+2

pw::allocator::BucketBlockAllocator<>::ReserveBlock()

+30

pw::allocator::BlockAllocator<>::NextIsFree()

+28

pw::allocator::BlockAllocator<>::UpdateLast()

+2

pw::allocator::Block<>::Iterator::operator++()

+16

pw::allocator::Block<>::Next()

+14

pw::allocator::Block<>::Prev()

+2

pw::allocator::internal::Bucket::Bucket()

+16

pw::Deallocator::DoGetInfo()

+8

pw::allocator::internal::GenericBlockAllocator::kCapabilities

+2

pw::allocator::BlockAllocator<>::RecycleBlock()

+2

pw::allocator::BlockAllocator<>::ReserveBlock()

NEW

+244

pw::allocator::LastFitBlockAllocator<>::ChooseBlock()

NEW

+64

pw::allocator::LastFitBlockAllocator<>

NEW

+64

pw::allocator::LastFitBlockAllocator<>::~LastFitBlockAllocator()

+1,840

LibCAllocator

FLASH

+4

quorem

-8

pw::allocator::NullAllocator

+2

pw::allocator::BucketBlockAllocator<>::ReserveBlock()

NEW

+66

__wrap_realloc

NEW

+60

pw::allocator::GetLibCAllocator()

NEW

+56

pw::allocator::LibCAllocator

NEW

+28

pw::allocator::LibCAllocator::DoReallocate()

NEW

+26

pw::allocator::LibCAllocator::DoAllocate()

NEW

+22

pw::allocator::LibCAllocator::DoDeallocate()

NEW

+16

pw::allocator::LibCAllocator::~LibCAllocator()

+272

WorstFitBlockAllocator

FLASH

+4

quorem

+212

pw::allocator::Block<>::Resize()

+118

main

+158

pw::allocator::BlockAllocator<>::DoGetInfo()

+148

pw::allocator::BlockAllocator<>::DoDeallocate()

+128

pw::allocator::Block<>::CanAllocLast()

+114

pw::allocator::BlockAllocator<>::DoResize()

+116

pw::allocator::Block<>::Split()

+88

pw::allocator::Block<>::MergeNext()

+90

pw::allocator::Block<>::Free()

+88

pw::allocator::Block<>::CrashIfInvalid()

+72

pw::allocator::BlockAllocator<>::Init()

+64

pw::allocator::BlockAllocator<>

+46

pw::allocator::BlockAllocator<>::FromUsableSpace<>()

+40

pw::allocator::BlockAllocator<>::DoAllocate()

+2

pw::allocator::BucketBlockAllocator<>::ReserveBlock()

+30

pw::allocator::BlockAllocator<>::NextIsFree()

+28

pw::allocator::BlockAllocator<>::UpdateLast()

-2

pw_boot_PreStaticMemoryInit

+2

pw::allocator::Block<>::Iterator::operator++()

+16

pw::allocator::Block<>::Next()

+14

pw::allocator::Block<>::Prev()

+2

pw::allocator::internal::Bucket::Bucket()

+16

pw::Deallocator::DoGetInfo()

+2

pw::allocator::BlockAllocator<>::RecycleBlock()

+2

pw::allocator::BlockAllocator<>::ReserveBlock()

NEW

+210

pw::allocator::WorstFitBlockAllocator<>::ChooseBlock()

NEW

+64

pw::allocator::WorstFitBlockAllocator<>

NEW

+64

pw::allocator::WorstFitBlockAllocator<>::~WorstFitBlockAllocator()

+1,936

Forwarding allocators implementations#

The following are code sizes for each of the provided “forwarding” allocators as described by Forwarding allocator concept. These are measured by having the forwarding allocator wrap a FirstFitBlockAllocator, and are measured relative to that implementation.

Label

Segment

Delta

AsPmrAllocator

FLASH

-28

[section .code]

DEL

-284

std::vector<>::_M_realloc_insert<>()

-4

quorem

-8

main

-2

pw::Allocator::DoReallocate()

-36

operator new()

-2

pw::allocator::BlockAllocator<>::DoAllocate()

+2

pw::allocator::Block<>::Iterator::operator++()

+2

pw_boot_PreStaticMemoryInit

-8

pw::allocator::internal::GenericBlockAllocator::kCapabilities

-2

std::pmr::(anonymous namespace)::null_res_t::do_allocate()

DEL

-6

std::__throw_length_error()

NEW

+56

pw::allocator::internal::MemoryResource::do_allocate()

NEW

+40

pw::allocator::internal::MemoryResource::~MemoryResource()

NEW

+36

pw::allocator::internal::MemoryResource

NEW

+26

std::_Vector_base<>::_M_deallocate()

NEW

+12

pw::allocator::internal::MemoryResource::do_deallocate()

NEW

+10

pw::allocator::internal::MemoryResource::do_is_equal()

NEW

+4

std::pmr::memory_resource::~memory_resource()

-192

FallbackAllocator

FLASH

+16

main

+2

pw_boot_PreStaticMemoryInit

-8

pw::allocator::internal::GenericBlockAllocator::kCapabilities

NEW

+186

pw::allocator::FallbackAllocator::DoGetInfo()

NEW

+74

pw::allocator::FallbackAllocator::DoAllocate()

NEW

+56

pw::allocator::FallbackAllocator

NEW

+46

pw::allocator::FallbackAllocator::DoDeallocate()

NEW

+44

pw::allocator::FallbackAllocator::FallbackAllocator()

NEW

+32

pw::Deallocator::Recognizes()

NEW

+32

pw::allocator::FallbackAllocator::DoResize()

NEW

+24

pw::Allocator::Resize()

NEW

+16

pw::allocator::FallbackAllocator::~FallbackAllocator()

+520

SynchronizedAllocator<sync::InterruptSpinLock>

FLASH

-4

quorem

-2

pw::allocator::BlockAllocator<>::DoResize()

+2

pw_boot_PreStaticMemoryInit

NEW

+56

pw::allocator::SynchronizedAllocator<>::DoDeallocate()

NEW

+54

pw::allocator::SynchronizedAllocator<>::DoReallocate()

NEW

+48

pw::allocator::SynchronizedAllocator<>

NEW

+48

pw::allocator::SynchronizedAllocator<>::DoAllocate()

NEW

+48

pw::allocator::SynchronizedAllocator<>::DoGetInfo()

NEW

+46

pw::Allocator::Reallocate()

NEW

+46

pw::allocator::SynchronizedAllocator<>::DoResize()

NEW

+44

pw::sync::Borrowable<>::acquire()

NEW

+24

pw::Allocator::Resize()

NEW

+16

pw::allocator::SynchronizedAllocator<>::~SynchronizedAllocator()

NEW

+14

pw::sync::BorrowedPointer<>::~BorrowedPointer()

+440

SynchronizedAllocator<sync::Mutex>

FLASH

-2

pw::allocator::BlockAllocator<>::DoResize()

NEW

+56

pw::allocator::SynchronizedAllocator<>::DoDeallocate()

NEW

+54

pw::allocator::SynchronizedAllocator<>::DoReallocate()

NEW

+48

pw::allocator::SynchronizedAllocator<>

NEW

+48

pw::allocator::SynchronizedAllocator<>::DoAllocate()

NEW

+48

pw::allocator::SynchronizedAllocator<>::DoGetInfo()

NEW

+46

pw::Allocator::Reallocate()

NEW

+46

pw::allocator::SynchronizedAllocator<>::DoResize()

NEW

+44

pw::sync::Borrowable<>::acquire()

NEW

+44

pw::sync::BorrowedPointer<>::~BorrowedPointer()

NEW

+24

pw::Allocator::Resize()

NEW

+16

pw::allocator::SynchronizedAllocator<>::~SynchronizedAllocator()

+472

TrackingAllocator<AllMetrics>

FLASH

+12

main

-2

pw::allocator::BlockAllocator<>::DoResize()

-2

pw::allocator::Block<>::Iterator::operator++()

NEW

+360

pw::allocator::internal::Metrics<>::Metrics()

NEW

+188

pw::allocator::TrackingAllocator<>::~TrackingAllocator()

NEW

+168

pw::allocator::TrackingAllocator<>::DoReallocate()

NEW

+132

pw::allocator::TrackingAllocator<>::DoResize()

NEW

+108

pw::allocator::TrackingAllocator<>::DoDeallocate()

NEW

+104

pw::allocator::TrackingAllocator<>::DoAllocate()

NEW

+80

pw::allocator::internal::Metrics<>::ModifyAllocated()

NEW

+80

pw::allocator::internal::Metrics<>::ModifyRequested()

NEW

+48

pw::allocator::TrackingAllocator<>

NEW

+46

pw::Allocator::Reallocate()

NEW

+40

pw::metric::Metric::Increment()

NEW

+36

pw::metric::Metric::Decrement()

NEW

+32

pw::containers::internal::GenericIntrusiveList<>::~GenericIntrusiveList()

NEW

+30

pw::allocator::Layout::Unwrap()

NEW

+28

pw::allocator::internal::Metrics<>::RecordFailure()

NEW

+28

pw::metric::Metric::SetInt()

NEW

+28

pw::metric::Metric::as_int()

NEW

+26

pw::containers::internal::GenericIntrusiveList<>::insert_after()

NEW

+26

pw::containers::internal::LegacyIntrusiveList<>::Item::~Item()

NEW

+24

pw::Allocator::Resize()

NEW

+20

pw::containers::internal::CheckIntrusiveContainerIsEmpty()

NEW

+20

pw::containers::internal::CheckIntrusiveItemIsUncontained()

NEW

+20

pw::containers::internal::GenericIntrusiveList<>::clear()

NEW

+20

pw::containers::internal::IntrusiveListItemBase<>::unlist()

NEW

+18

pw::Deallocator::GetAllocatedLayout()

NEW

+18

pw::Deallocator::GetRequestedLayout()

NEW

+16

pw::allocator::TrackingAllocator<>::DoGetInfo()

+1,752

TrackingAllocator<NoMetrics>

FLASH

+16

main

-4

quorem

-2

pw::allocator::BlockAllocator<>::DoResize()

+2

pw_boot_PreStaticMemoryInit

NEW

+104

pw::allocator::TrackingAllocator<>::~TrackingAllocator()

NEW

+90

pw::allocator::TrackingAllocator<>::DoReallocate()

NEW

+76

pw::allocator::TrackingAllocator<>::DoResize()

NEW

+58

pw::allocator::TrackingAllocator<>::DoDeallocate()

NEW

+50

pw::allocator::TrackingAllocator<>::DoAllocate()

NEW

+48

pw::allocator::TrackingAllocator<>

NEW

+46

pw::Allocator::Reallocate()

NEW

+34

pw::containers::internal::GenericIntrusiveList<>::~GenericIntrusiveList()

NEW

+30

pw::allocator::Layout::Unwrap()

NEW

+24

pw::Allocator::Resize()

NEW

+20

pw::containers::internal::CheckIntrusiveContainerIsEmpty()

NEW

+20

pw::containers::internal::CheckIntrusiveItemIsUncontained()

NEW

+18

pw::Deallocator::GetAllocatedLayout()

NEW

+18

pw::Deallocator::GetRequestedLayout()

NEW

+16

pw::allocator::TrackingAllocator<>::DoGetInfo()

+664