Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CheapMeow opened this issue Apr 1, 2024 · 0 comments

Comments

@CheapMeow
Copy link

CheapMeow commented Apr 1, 2024

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;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant