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

Fix to avoid allocation/garbage when submitting OpenAL buffers. #8178

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

ParanoidCactus
Copy link
Contributor

This is a minor change to prevent a new int array from being allocated every time DynamicSoundEffectInstance.SubmitBuffer() is called.

I found this by running a performance profile on a project I'm working on that uses DynamicSoundEffectInstance for the audio. It was allocating over 2000 arrays in 15 seconds.

For reference the previous version was calling the below method and always passing in 1 as the count. So this is just doing the exact same thing without allocating a new array on the heap.

internal unsafe static void GenBuffers(int count, out int[] buffers)
{
    buffers = new int[count];
    fixed (int* ptr = &buffers[0])
    {
        alGenBuffers(count, ptr);
    }
}

Copy link
Contributor

@dellis1972 dellis1972 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good fix :) Not allocating stuff is a good thing :D
I'll let @harry-cpp or @mrhelmut comment as well.

@tomspilman
Copy link
Member

Looks great to me! Good job @ParanoidCactus

@mrhelmut mrhelmut merged commit c6e47a1 into MonoGame:develop Feb 15, 2024
4 checks passed
@mrhelmut
Copy link
Contributor

It's a welcome tweak, merging!

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

Successfully merging this pull request may close these issues.

None yet

4 participants