Exemple #1
0
        public FlatArray(Message msg, int count, out AllocationContext allocContext) : this()
        {
            var elementSize = this.GetElementSize();

            // TODO: handle composite
            if (elementSize == ElementSize.Composite)
            {
                int words = 1 + count * (ReflectionCache <T> .KnownDataWords + ReflectionCache <T> .KnownPointerWords);

                msg.Allocate(
                    words,
                    out var offset,
                    out var segment);

                segment[offset | Word.unit] = new StructPointer
                {
                    Type         = PointerType.Struct,
                    WordOffset   = count,
                    DataWords    = ReflectionCache <T> .KnownDataWords,
                    PointerWords = ReflectionCache <T> .KnownPointerWords,
                }.RawValue;

                allocContext = new AllocationContext(segment, offset + 1, words - 1);

                _pointer = new AbsPointer(
                    segment,
                    0,
                    new ListPointer
                {
                    Type         = PointerType.List,
                    WordOffset   = offset,
                    ElementSize  = elementSize,
                    ElementCount = (uint)words - 1
                });
            }
            else
            {
                int words = TypeHelpers.SizeOf(elementSize) * count / 8;
                msg.Allocate(
                    words,
                    out var offset,
                    out var segment);

                allocContext = new AllocationContext(segment, offset, words);

                _pointer = new AbsPointer(
                    segment,
                    0,
                    new ListPointer
                {
                    Type         = PointerType.List,
                    WordOffset   = offset,
                    ElementSize  = elementSize,
                    ElementCount = (uint)count
                });
            }
        }
Exemple #2
0
        public CompositeList(Message msg, int count, out AllocationContext allocContext)
        {
            var tag = new StructPointer
            {
                Type         = PointerType.Struct,
                WordOffset   = 0,
                DataWords    = ReflectionCache <T> .KnownDataWords,
                PointerWords = ReflectionCache <T> .KnownPointerWords,
            };

            _elementCount = 0;
            _dataWords    = tag.DataWords;
            _pointerWords = tag.PointerWords;
            var elementWords = count * (_dataWords + _pointerWords);

            msg.Allocate(elementWords + 1, out _tagOffset, out _segment);
            allocContext = new AllocationContext(_segment, _tagOffset + 1, elementWords);
            _segment[_tagOffset | Word.unit] = tag.RawValue;
        }
Exemple #3
0
 public Text(Message msg, int bytesWithNulTerminator, out AllocationContext allocContext)
 {
     _bytes = new FlatArray <byte>(msg, bytesWithNulTerminator, out allocContext);
 }
Exemple #4
0
 public Data(Message msg, int length, out AllocationContext allocContext)
 {
     _bytes = new FlatArray <byte>(msg, length, out allocContext);
 }