Chunk of misc data

Hi,

Trying to implement something to use in a pipeline where inputs could be math types (mainly float-float4 in this test). Just your thoughts on what I could do here better? Basically I want a struct where [0] might refer to a float2, [1] might be a float3, using a 128 byte buffer. Also no idea when used in a separate op job, how burst will like it. No idea if this would be better using a NativeArray. Iโ€™m no expert, but just looking to expand my knowledge from experts :slight_smile:

    public struct Floats
    {
        fixed byte store[128];
        fixed int offset[32];
        int remaining;
        int pos;
        int current;

        public void Init()
        {
            remaining = 128;
            pos = 0;
            current = 0;
        }

        public void Set<T>(T someValue) where T : unmanaged
        {
            var size = sizeof(T);
            if (size < remaining)
            {
                fixed(void* p = &store[current]) *(T*)p = someValue;
                current += size;
                offset[pos + 1] = offset[pos++] + size;
                remaining -= size;
            }
        }

        public T Get<T>(int i) where T : unmanaged
        {
            fixed (void* f = &store[offset[i]]) return *(T*)f;
        }
    }

Why not use NativeStream or UnsafeStream? You can append arbitrary types to it and then read them. Seems similar to what you want.

@CookieStealer2 Yes I do want to convert over to the Native libraries if I get what I want working. That does look like it might be useful if itโ€™s indexes each piece of data of misc length, to work with another index of commands. At this point it is more about the model.