Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Oct 15, 2024
1 parent 647cd08 commit 0018e4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion source/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ namespace Langulus::Fractalloc
Logger::Warning(
"Fractalloc: Suspicious reference count in allocation ",
Logger::Hex(allocation), " of size ", allocation->GetAllocatedSize(),
" in pool ", Logger::Hex(pool)
" in pool ", Logger::Hex(pool), ", entry #", i, " of ", pool->mEntries
);
}

Expand Down
2 changes: 0 additions & 2 deletions source/Pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace Langulus::Fractalloc
Count mEntries {};
// A chain of freed entries in the range [0-mEntries)
Allocation* mLastFreed {};
// The next usable entry (not allocated yet)
//Byte* mNextEntry {};
// Current threshold, that is, max size of a new entry
Offset mThreshold {};
Offset mThresholdPrevious {};
Expand Down
32 changes: 9 additions & 23 deletions source/Pool.inl
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ namespace Langulus::Fractalloc
/// @param memory - handle for use with std::free()
LANGULUS(INLINED)
Pool::Pool(DMeta meta, Offset size, void* memory) noexcept
: mAllocatedByBackend {size}
: mAllocatedByBackend {size}
, mAllocatedByBackendLog2 {Inner::FastLog2(size)}
, mAllocatedByBackendLSB {Inner::LSB(size >> Offset {1})}
, mThreshold {size}
, mThresholdPrevious {size}
, mThresholdMin {Roof2(meta
, mThreshold {size}
, mThresholdPrevious {size}
, mThresholdMin {Roof2(meta
? meta->mAllocationPage.mSize
: Allocation::GetMinAllocation())}
, mMeta {meta}
, mHandle {memory} {
, mMeta {meta}
, mHandle {memory}
{
mMemory = GetPoolStart<Byte>();
mMemoryEnd = mMemory + mAllocatedByBackend;
//mNextEntry = mMemory;

#if LANGULUS_FEATURE(MEMORY_STATISTICS)
mStep = Instance.GetStatistics().mStep;
Expand Down Expand Up @@ -132,8 +132,6 @@ namespace Langulus::Fractalloc
/// @param bytes - number of bytes to allocate
/// @return the new allocation, or nullptr if pool is full
inline Allocation* Pool::Allocate(const Offset bytes) IF_UNSAFE(noexcept) {
constexpr Offset one = 1;

// Check if we can add a new entry
const auto bytesWithPadding = Allocation::GetNewAllocationSize(bytes);
if (not CanContain(bytesWithPadding))
Expand All @@ -151,25 +149,17 @@ namespace Langulus::Fractalloc
else {
// The entire pool is full (or empty), skip search for free
// spot, add a new allocation directly instead
newEntry = const_cast<Allocation*>(AllocationFromIndex(mEntries)); //reinterpret_cast<Allocation*>(mNextEntry);
newEntry = const_cast<Allocation*>(AllocationFromIndex(mEntries));
new (newEntry) Allocation {
bytesWithPadding - Allocation::GetSize(), this
};

++mEntries;

// Move carriage to the next entry
//mNextEntry += mThresholdPrevious;

if (reinterpret_cast<Byte*>(newEntry) + mThreshold >= mMemoryEnd) {
// Reset carriage and shift level when it goes beyond
mThresholdPrevious = mThreshold;
mThreshold >>= one;
//mNextEntry = mMemory + mThreshold;
//mNextEntry = const_cast<Byte*>(reinterpret_cast<const Byte*>(AllocationFromIndex(mEntries)));

//if (const_cast<Byte*>(reinterpret_cast<const Byte*>(AllocationFromIndex(mEntries))) != mNextEntry)
// Logger::Error("WRONG WRONG WRONG WRONG WRONG WRONG WRONG WRONG WRONG WRONG WRONG");
mThreshold /= 2;
}
}

Expand Down Expand Up @@ -206,7 +196,6 @@ namespace Langulus::Fractalloc
mThresholdMin = Allocation::GetMinAllocation();
mLastFreed = nullptr;
mEntries = 0;
//mNextEntry = mMemory;
IF_LANGULUS_MEMORY_STATISTICS(mValidEntries = 0);
}
else {
Expand Down Expand Up @@ -348,9 +337,6 @@ namespace Langulus::Fractalloc
mThreshold = ThresholdFromIndex(mEntries - 1);
mThresholdPrevious = mThreshold != mAllocatedByBackend
? Offset {mThreshold * 2} : mThreshold;
/*mNextEntry = const_cast<Byte*>(
reinterpret_cast<const Byte*>(AllocationFromIndex(mEntries))
);*/
}

/// Get threshold associated with an index
Expand Down

0 comments on commit 0018e4e

Please sign in to comment.