ABT.Utils.RoundUp C# (CSharp) Метод

RoundUp() публичный статический Метод

public static RoundUp ( Int32 value, Int32 alignment ) : Int32
value System.Int32
alignment System.Int32
Результат System.Int32
        public static Int32 RoundUp(Int32 value, Int32 alignment) {
            return (value + alignment - 1) & ~(alignment- 1);
        }

Usage Example

Пример #1
0
            public void DefineStruct(IReadOnlyList <Tuple <String, ExprType> > attribs)
            {
                if (this.IsComplete)
                {
                    throw new InvalidOperationException("Cannot redefine a struct.");
                }

                this._attribs = new List <Utils.StoreEntry>();
                Int32 offset           = 0;
                Int32 struct_alignment = 0;

                foreach (Tuple <String, ExprType> attrib in attribs)
                {
                    String   name = attrib.Item1;
                    ExprType type = attrib.Item2;

                    Int32 attrib_alignment = type.Alignment;

                    // All attributes must be aligned.
                    // This means that the alignment of the struct is the largest attribute alignment.
                    struct_alignment = Math.Max(struct_alignment, attrib_alignment);

                    // Make sure all attributes are put into aligned places.
                    offset = Utils.RoundUp(offset, attrib_alignment);

                    this._attribs.Add(new Utils.StoreEntry(name, type, offset));

                    offset += type.SizeOf;
                }

                this._size_of = Utils.RoundUp(offset, struct_alignment);
            }
All Usage Examples Of ABT.Utils::RoundUp