[*] Fix: AuByteBuffer::Resize could resize with wrong ringbuffer alignmnet or linear if a fast path fails

[+] ByteBuffer::ByteBuffer(const MemoryViewRead &readView, AuUInt uAlignment, bool circular, bool expandable
This commit is contained in:
Reece Wilson 2024-06-03 04:23:51 +01:00
parent 3241ebb349
commit ee9e318511
3 changed files with 27 additions and 3 deletions

View File

@ -125,6 +125,8 @@ namespace Aurora::Memory
inline ByteBuffer(const MemoryViewRead &readView, bool circular = false, bool expandable = false);
inline ByteBuffer(const MemoryViewRead &readView, AuUInt uAlignment, bool circular = false, bool expandable = false);
inline ByteBuffer(const AuList<AuUInt8> &vector, bool circular = false, bool expandable = false);
inline ByteBuffer(AuUInt length, bool circular = false, bool expandable = false);

View File

@ -297,13 +297,12 @@ namespace Aurora::Memory
}
}
ByteBuffer replacement(length, (bool)this->flagCircular, (bool)this->flagExpandable);
ByteBuffer replacement(length, this->alignment, (bool)this->flagCircular, (bool)this->flagExpandable);
if (!replacement)
{
return false;
}
replacement.flagAlwaysExpandable = this->flagAlwaysExpandable;
replacement.alignment = this->alignment;
AuUInt uBytesRem {};
if (!this->flagCircular && length < (uBytesRem = this->RemainingBytes()))

View File

@ -313,6 +313,29 @@ namespace Aurora::Memory
AuMemcpy(this->base, vector.data(), this->length);
}
ByteBuffer::ByteBuffer(const MemoryViewRead &readView, AuUInt uAlignment, bool circular, bool expandable) :
flagCircular(circular), flagExpandable(expandable), flagReadError(0), flagWriteError(0)
{
this->scaleSize = kBufferInitialPower;
if (!length)
{
Reset();
return;
}
this->base = ZAlloc<AuUInt8 *>(length, alignment);
this->alignment = uAlignment;
if (!this->base)
{
Reset();
return;
}
this->length = length;
this->allocSize = length;
this->readPtr = this->base;
this->writePtr = this->readPtr + this->length;
AuMemcpy(this->base, readView.Begin(), length);
}
ByteBuffer::ByteBuffer(AuUInt length, bool circular, bool expandable) :
flagCircular(circular), flagExpandable(expandable), flagReadError(0), flagWriteError(0)
{