コード例 #1
0
        //====================================================================
        // SizeOf()
        //====================================================================
        //| <include path='docs/doc[@for="Marshal.SizeOf"]/*' />
        // TODO PORTING: For 64 bit port, Ati considered making SizeOf return an IntPtr instead of an Int.  Consider making that change AND updating ECALL method sig.
        public static int SizeOf(Object structure)
        {
            VTable vtable = structure.vtable;

            if (vtable.arrayOf == StructuralType.None)
            {
                if (vtable.Equals("string".vtable))
                {
                    throw new Exception("SizeOf not implemented for string objects");
                }
                else
                {
                    return(vtable.marshalSize);
                }
            }
            else
            {
                int elementSize = vtable.arrayElementSize;
                int elementMask = elementSize - 1;
                int numElements = ((Array)structure).Length;
                return(((int)vtable.baseLength +
                        numElements * elementSize +
                        elementMask) & ~elementMask);
            }
        }