• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Modules.MemoryHolder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IronPython.Modules.MemoryHolder的典型用法代码示例。如果您正苦于以下问题:C# MemoryHolder类的具体用法?C# MemoryHolder怎么用?C# MemoryHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MemoryHolder类属于IronPython.Modules命名空间,在下文中一共展示了MemoryHolder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: MemoryHolder

 /// <summary>
 /// Creates a new MemoryHolder at the specified address which will keep alive the 
 /// parent memory holder.
 /// </summary>
 public MemoryHolder(IntPtr data, int size, MemoryHolder parent) {
     GC.SuppressFinalize(this);
     _data = data;
     _parent = parent;
     _objects = parent._objects;
     _size = size;
 }
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:11,代码来源:MemoryHolder.cs


示例2: __init__

 public void __init__(object value) {
     _memHolder = new MemoryHolder(Size);
     NativeType.SetValue(_memHolder, 0, value);
     if (IsString) {
         _memHolder.AddObject("str", value);
     }
 }
开发者ID:TerabyteX,项目名称:ironpython3,代码行数:7,代码来源:SimpleCData.cs


示例3: Pointer

 public Pointer(CData value) {
     _object = value; // Keep alive the object, more to do here.
     _memHolder = new MemoryHolder(IntPtr.Size);
     _memHolder.WriteIntPtr(0, value._memHolder);
     _memHolder.AddObject("1", value);
     if (value._objects != null) {
         _memHolder.AddObject("0", value._objects);
     }
 }
开发者ID:nieve,项目名称:ironruby,代码行数:9,代码来源:Pointer.cs


示例4: __init__

            public void __init__(params object[] args) {
                CheckAbstract();

                INativeType nativeType = NativeType;
                StructType st = (StructType)nativeType;

                _memHolder = new MemoryHolder(nativeType.Size);
                st.SetValueInternal(_memHolder, 0, args);
            }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:9,代码来源:Structure.cs


示例5: __init__

            public void __init__(params object[] args) {
                INativeType nativeType = NativeType;

                _memHolder = new MemoryHolder(nativeType.Size);

                if (args.Length > ((ArrayType)nativeType).Length) {
                    throw PythonOps.IndexError("too many arguments");
                }
                nativeType.SetValue(_memHolder, 0, args);
            }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:10,代码来源:Array.cs


示例6: WriteIntPtr

 public void WriteIntPtr(int offset, MemoryHolder address) {
     Marshal.WriteIntPtr(_data, offset, address.UnsafeAddress);
     GC.KeepAlive(this);
     GC.KeepAlive(address);
 }
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:5,代码来源:MemoryHolder.cs


示例7: NotImplementedException

 object INativeType.GetValue(MemoryHolder owner, int offset, bool raw) {
     throw new NotImplementedException("union get value");
 }
开发者ID:xerxesb,项目名称:ironruby,代码行数:3,代码来源:UnionType.cs


示例8: WriteString

            private void WriteString(MemoryHolder address, int offset, string str) {
                SimpleType st = (SimpleType)_type;
                if (str.Length < _length) {
                    str = str + '\x00';
                }
                if (st._type == SimpleTypeKind.Char) {
                    address.WriteAnsiString(offset, str);
                } else {
                    address.WriteUnicodeString(offset, str);
                }

            }
开发者ID:techarch,项目名称:ironruby,代码行数:12,代码来源:ArrayType.cs


示例9: switch

            object INativeType.GetValue(MemoryHolder/*!*/ owner, object readingFrom, int offset, bool raw) {
                object res;
                switch (_type) {
                    case SimpleTypeKind.Boolean: res = owner.ReadByte(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;
                    case SimpleTypeKind.Char: res = new string((char)owner.ReadByte(offset), 1); break;
                    case SimpleTypeKind.SignedByte: res = GetIntReturn((int)(sbyte)owner.ReadByte(offset)); break;
                    case SimpleTypeKind.UnsignedByte: res = GetIntReturn((int)owner.ReadByte(offset)); break;
                    case SimpleTypeKind.SignedShort: res = GetIntReturn((int)owner.ReadInt16(offset)); break;
                    case SimpleTypeKind.WChar: res = new string((char)owner.ReadInt16(offset), 1); break;
                    case SimpleTypeKind.UnsignedShort: res = GetIntReturn((int)(ushort)owner.ReadInt16(offset)); break;
                    case SimpleTypeKind.VariantBool: res = owner.ReadInt16(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;
                    case SimpleTypeKind.SignedInt: res = GetIntReturn((int)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.UnsignedInt: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.UnsignedLong: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.SignedLong: res = GetIntReturn(owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.Single: res = GetSingleReturn(owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.Double: res = GetDoubleReturn(owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.UnsignedLongLong: res = GetIntReturn((ulong)owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.SignedLongLong: res = GetIntReturn(owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.Object: res = GetObjectReturn(owner.ReadIntPtr(offset)); break;
                    case SimpleTypeKind.Pointer: res = owner.ReadIntPtr(offset).ToPython(); break;
                    case SimpleTypeKind.CharPointer: res = owner.ReadMemoryHolder(offset).ReadAnsiString(0); break;
                    case SimpleTypeKind.WCharPointer: res = owner.ReadMemoryHolder(offset).ReadUnicodeString(0); break;
                    default:
                        throw new InvalidOperationException();
                }

                if (!raw && IsSubClass) {
                    res = PythonCalls.Call(this, res);
                }

                return res;
            }
开发者ID:jschementi,项目名称:iron,代码行数:33,代码来源:SimpleType.cs


示例10: SetBitsValue

            /// <summary>
            /// Called for fields which have been limited to a range of bits.  Sets the 
            /// specified value into the bits for the field.
            /// </summary>
            private void SetBitsValue(MemoryHolder address, int baseOffset, object value) {
                // get the value in the form of a ulong which can contain the biggest bitfield
                ulong newBits;
                if (value is int) {
                    newBits = (ulong)(int)value;
                } else if (value is BigInteger) {
                    newBits = (ulong)(long)(BigInteger)value;
                } else {
                    throw PythonOps.TypeErrorForTypeMismatch("int or long", value);
                }

                // do the same for the existing value
                int offset = checked(_offset + baseOffset);
                object curValue = _fieldType.GetValue(address, null, offset, false);
                ulong valueBits;
                if (curValue is int) {
                    valueBits = (ulong)(int)curValue;
                } else {
                    valueBits = (ulong)(long)(BigInteger)curValue;
                }

                // get a mask for the bits this field owns
                ulong targetBits = ((1UL << _bits) - 1) << _bitsOffset;
                // clear the existing bits
                valueBits &= ~targetBits;
                // or in the new bits provided by the user
                valueBits |= (newBits << _bitsOffset) & targetBits;

                // and set the value                    
                if (IsSignedType) {
                    if (_fieldType.Size <= 4) {
                        _fieldType.SetValue(address, offset, (int)(long)valueBits);
                    } else {
                        _fieldType.SetValue(address, offset, (BigInteger)(long)valueBits);
                    }
                } else {
                    if (_fieldType.Size < 4) {
                        _fieldType.SetValue(address, offset, (int)valueBits);
                    } else {
                        _fieldType.SetValue(address, offset, (BigInteger)valueBits);
                    }
                }
            }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:47,代码来源:Field.cs


示例11: SetValue

 internal void SetValue(MemoryHolder address, int baseOffset, object value) {
     if (_bits == -1) {
         object keepAlive = _fieldType.SetValue(address, baseOffset + _offset, value);
         if (keepAlive != null) {
             address.AddObject(_index.ToString(), keepAlive);
         }
     } else {
         SetBitsValue(address, baseOffset, value);
     }
 }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:10,代码来源:Field.cs


示例12: checked

            object INativeType.GetValue(MemoryHolder owner, int offset, bool raw) {
                if (IsStringType) {
                    SimpleType st = (SimpleType)_type;
                    string str;
                    if (st._type == SimpleTypeKind.Char) {
                        str = owner.ReadAnsiString(offset, _length);
                    } else {
                        str = owner.ReadUnicodeString(offset, _length);
                    }

                    // remove any trailing nulls
                    for (int i = 0; i < str.Length; i++) {
                        if (str[i] == '\x00') {
                            return str.Substring(0, i);
                        }
                    }

                    return str;
                }

                object[] res = new object[_length];
                for (int i = 0; i < res.Length; i++) {
                    res[i] = _type.GetValue(owner, checked(offset + _type.Size * i), raw);
                }

                return List.FromArrayNoCopy(res);
            }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:27,代码来源:ArrayType.cs


示例13: __init__

 public void __init__(object value) {
     _memHolder = new MemoryHolder(Size);
     NativeType.SetValue(_memHolder, 0, value);
 }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:4,代码来源:SimpleCData.cs


示例14: if

            object INativeType.SetValue(MemoryHolder address, int offset, object value) {
                Pointer ptr;
                _Array array;
                if (value == null) {
                    address.WriteIntPtr(offset, IntPtr.Zero);
                }  else if (value is int) {
                    address.WriteIntPtr(offset, new IntPtr((int)value));
                } else if (value is BigInteger) {
                    address.WriteIntPtr(offset, new IntPtr((long)(BigInteger)value));
                } else if ((ptr = value as Pointer) != null) {
                    address.WriteIntPtr(offset, ptr._memHolder.ReadMemoryHolder(0));
                    return PythonOps.MakeDictFromItems(ptr, "0", ptr._objects, "1");
                } else if ((array = value as _Array) != null) {
                    address.WriteIntPtr(offset, array._memHolder);
                    return array;
                } else {
                    throw PythonOps.TypeErrorForTypeMismatch(Name, value);
                }

                return null;
            }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:21,代码来源:PointerType.cs


示例15: GetRawValue

            internal string GetRawValue(MemoryHolder owner, int offset) {
                Debug.Assert(IsStringType);
                SimpleType st = (SimpleType)_type;
                string str;
                if (st._type == SimpleTypeKind.Char) {
                    str = owner.ReadAnsiString(offset, _length);
                } else {
                    str = owner.ReadUnicodeString(offset, _length);
                }

                return str;
            }
开发者ID:techarch,项目名称:ironruby,代码行数:12,代码来源:ArrayType.cs


示例16: if

            object INativeType.SetValue(MemoryHolder address, int offset, object value) {
                string str = value as string;
                if (str != null) {
                    if (!IsStringType) {
                        throw PythonOps.TypeError("expected {0} instance, got str", Name);
                    } else if (str.Length > _length) {
                        throw PythonOps.ValueError("string too long ({0}, maximum length {1})", str.Length, _length);
                    }

                    WriteString(address, offset, str);

                    return null;
                } else if (IsStringType) {
                    IList<object> objList = value as IList<object>;
                    if (objList != null) {
                        StringBuilder res = new StringBuilder(objList.Count);
                        foreach (object o in objList) {
                            res.Append(Converter.ConvertToChar(o));
                        }

                        WriteString(address, offset, res.ToString());
                        return null;
                    }

                    throw PythonOps.TypeError("expected string or Unicode object, {0} found", DynamicHelpers.GetPythonType(value).Name);
                }

                object[] arrArgs = value as object[];
                if (arrArgs == null) {
                    PythonTuple pt = value as PythonTuple;
                    if (pt != null) {
                        arrArgs = pt._data;
                    }

                }

                if (arrArgs != null) {
                    if (arrArgs.Length > _length) {
                        throw PythonOps.RuntimeError("invalid index");
                    }

                    for (int i = 0; i < arrArgs.Length; i++) {
                        _type.SetValue(address, checked(offset + i * _type.Size), arrArgs[i]);
                    }
                } else {
                    _Array arr = value as _Array;
                    if (arr != null && arr.NativeType == this) {
                        arr._memHolder.CopyTo(address, offset, ((INativeType)this).Size);
                        return arr._memHolder.EnsureObjects();
                    }

                    throw PythonOps.TypeError("unexpected {0} instance, got {1}", Name, DynamicHelpers.GetPythonType(value).Name);
                }

                return null;
            }
开发者ID:techarch,项目名称:ironruby,代码行数:56,代码来源:ArrayType.cs


示例17: ReadChar

 /// <summary>
 /// Helper function for reading char/wchar's.  This is used for reading from
 /// arrays and pointers to avoid creating lots of 1-char strings.
 /// </summary>
 internal char ReadChar(MemoryHolder/*!*/ owner, int offset) {
     switch (_type) {
         case SimpleTypeKind.Char: return (char)owner.ReadByte(offset);
         case SimpleTypeKind.WChar: return (char)owner.ReadInt16(offset);
         default: throw new InvalidOperationException();
     }
 }
开发者ID:jschementi,项目名称:iron,代码行数:11,代码来源:SimpleType.cs


示例18: CreateMemoryHolder

 public static object CreateMemoryHolder(IntPtr data, int size) {
     var res = new MemoryHolder(size);
     res.CopyFrom(data, new IntPtr(size));
     return res;
 }
开发者ID:nieve,项目名称:ironruby,代码行数:5,代码来源:ModuleOps.cs


示例19: InvalidOperationException

            object INativeType.SetValue(MemoryHolder/*!*/ owner, int offset, object value) {
                SimpleCData data = value as SimpleCData;
                if (data != null && data.NativeType == this) {
                    data._memHolder.CopyTo(owner, offset, ((INativeType)this).Size);
                    return null;
                }

                switch (_type) {
                    case SimpleTypeKind.Boolean: owner.WriteByte(offset, ModuleOps.GetBoolean(value, this)); break;
                    case SimpleTypeKind.Char: owner.WriteByte(offset, ModuleOps.GetChar(value, this)); break;
                    case SimpleTypeKind.SignedByte: owner.WriteByte(offset, ModuleOps.GetSignedByte(value, this)); break;
                    case SimpleTypeKind.UnsignedByte: owner.WriteByte(offset, ModuleOps.GetUnsignedByte(value, this)); break;
                    case SimpleTypeKind.WChar: owner.WriteInt16(offset, (short)ModuleOps.GetWChar(value, this)); break;
                    case SimpleTypeKind.SignedShort: owner.WriteInt16(offset, ModuleOps.GetSignedShort(value, this)); break;
                    case SimpleTypeKind.UnsignedShort: owner.WriteInt16(offset, ModuleOps.GetUnsignedShort(value, this)); break;
                    case SimpleTypeKind.VariantBool: owner.WriteInt16(offset, (short)ModuleOps.GetVariantBool(value, this)); break;
                    case SimpleTypeKind.SignedInt: owner.WriteInt32(offset, ModuleOps.GetSignedInt(value, this)); break;
                    case SimpleTypeKind.UnsignedInt: owner.WriteInt32(offset, ModuleOps.GetUnsignedInt(value, this)); break;
                    case SimpleTypeKind.UnsignedLong: owner.WriteInt32(offset, ModuleOps.GetUnsignedLong(value, this)); break;
                    case SimpleTypeKind.SignedLong: owner.WriteInt32(offset, ModuleOps.GetSignedLong(value, this)); break;
                    case SimpleTypeKind.Single: owner.WriteInt32(offset, ModuleOps.GetSingleBits(value)); break;
                    case SimpleTypeKind.Double: owner.WriteInt64(offset, ModuleOps.GetDoubleBits(value)); break;
                    case SimpleTypeKind.UnsignedLongLong: owner.WriteInt64(offset, ModuleOps.GetUnsignedLongLong(value, this)); break;
                    case SimpleTypeKind.SignedLongLong: owner.WriteInt64(offset, ModuleOps.GetSignedLongLong(value, this)); break;
                    case SimpleTypeKind.Object: owner.WriteIntPtr(offset, ModuleOps.GetObject(value)); break;
                    case SimpleTypeKind.Pointer: owner.WriteIntPtr(offset, ModuleOps.GetPointer(value)); break;
                    case SimpleTypeKind.CharPointer: 
                        owner.WriteIntPtr(offset, ModuleOps.GetCharPointer(value));
                        return value;
                    case SimpleTypeKind.WCharPointer: 
                        owner.WriteIntPtr(offset, ModuleOps.GetWCharPointer(value));
                        return value;
                    default:
                        throw new InvalidOperationException();
                }
                return null;
            }
开发者ID:jschementi,项目名称:iron,代码行数:37,代码来源:SimpleType.cs


示例20: SetAddress

 internal void SetAddress(IntPtr address) {
     Debug.Assert(_memHolder == null);
     _memHolder = new MemoryHolder(address, NativeType.Size);
 }
开发者ID:nieve,项目名称:ironruby,代码行数:4,代码来源:CData.cs



注:本文中的IronPython.Modules.MemoryHolder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Runtime.DictionaryStorage类代码示例发布时间:2022-05-26
下一篇:
C# Ast.Statement类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap