public static AllocatedPtr From(params Object[] args)
        {
            var size = args.Select(arg => Marshal.SizeOf(arg.GetType())).Sum();
            var ptr = new AllocatedPtr(size);
            int offset = 0;
            foreach (var arg in args)
            {
                // copy
                Marshal.StructureToPtr(arg, ptr.Ptr + offset, false);

                offset += Marshal.SizeOf(arg.GetType());
            }

            return ptr;
        }
 public static AllocatedPtr From(byte[] buffer)
 {
     var ptr = new AllocatedPtr(buffer.Length);
     Marshal.Copy(buffer, 0, ptr.Ptr, buffer.Length);
     return ptr;
 }
        public bool Set(String key, Object value)
        {
            foreach (var f in Fields)
            {
                if (f.Key == key)
                {
                    if (Buffer == null)
                    {
                        Buffer = new AllocatedPtr(Size);
                    }

                    // copy value
                    Marshal.StructureToPtr(value, Buffer.Ptr + f.Offset, false);

                    return true;
                }
            }
            return false;
        }