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

Consider adding Span<T> to UpdateBuffer #15

Open
xposure opened this issue Jul 17, 2019 · 2 comments
Open

Consider adding Span<T> to UpdateBuffer #15

xposure opened this issue Jul 17, 2019 · 2 comments

Comments

@xposure
Copy link

xposure commented Jul 17, 2019

I have a lot of low level code that creates memory outside of the heap. My entity system could be thought of like the new unity ECS using unmanaged structs in blocks.

Since i'm not working with standard c# arrays, it would be useful if I could pass a span to UpdateBuffer in place of an array.

@mellinoe
Copy link
Owner

I'm considering adding some Span overloads where it makes sense in the next version. In the meantime, you can use Spans with some of the existing overloads:

void UpdateBuffer<T>(DeviceBuffer buffer, uint bufferOffsetInBytes, ref T source, uint sizeInBytes);

// For example:
Span<uint> data = ...;
graphicsDevice.UpdateBuffer(buffer, offset, ref data[0], (uint)data.Length * sizeof(uint));

// You can also use the IntPtr overload if you pin your data:
void UpdateBuffer(DeviceBuffer buffer, uint bufferOffsetInBytes, IntPtr source, uint sizeInBytes);

@xposure
Copy link
Author

xposure commented Jul 17, 2019

@mellinoe Yea, I was going to note that I'm using the last option, since the memory is off the heap there is no need to pin it and I'm just passing the raw pointer wrapped in a IntPtr.

More of a quality of life suggestion than anything else.

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

2 participants