Skip to content

Why DVKRingBuffer set bufferOffset = 0, but not allocation size, when allocation is going to exceed the bufferSize? #176

@CheapMeow

Description

@CheapMeow

The ring buffer is defined as:

    class DVKRingBuffer
    {
        uint64 AllocateMemory(uint64 size)
        {
            uint64 allocationOffset = Align<uint64>(bufferOffset, minAlignment);

            if (allocationOffset + size <= bufferSize)
            {
                bufferOffset = allocationOffset + size;
                return allocationOffset;
            }

            bufferOffset = 0;
            return bufferOffset;
        }

When allocation is going to exceed the bufferSize allocationOffset + size > bufferSize, why bufferOffset = 0; but not bufferOffset = size? I think the latter is the right one, meaning that you reset your allocation to the start of inner buffer, and you have allocate size memory.

I think this is right:

    class DVKRingBuffer
    {
        uint64 AllocateMemory(uint64 size)
        {
            uint64 allocationOffset = Align<uint64>(bufferOffset, minAlignment);

            if (allocationOffset + size <= bufferSize)
            {
                bufferOffset = allocationOffset + size;
                return allocationOffset;
            }

            bufferOffset = size;
            return 0;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions