Как вернуть большую структуру будет дешевле?

158
23 октября 2021, 05:30

Допустим, некий код извлекает из указателя структуру. Структура имеет размер больше чем указатель/ссылка, будет ли дешевле обернуть эту структуру в класс, и вернуть ссылку на этот класс, и из него извлекать структуру, нежели возвращать эту структуру?

P.S. Такой вопрос появился, т.к. вспомнился один термин из документации, что если тип имеет размер больше чем размер ссылки/указателя, то его лучше возвращать/передавать по ссылке/указателю.

Одна из структур:

#region Usings
using System;
using System.Runtime.InteropServices;
#endregion
namespace libvlc.net
{
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct Event
    {
        internal readonly EventType Type;
        internal readonly IntPtr Caller;
        internal readonly EventData Data;
    }
    [StructLayout(LayoutKind.Explicit)]
    internal readonly struct EventData
    {
        [FieldOffset(0)] internal readonly MediaEvents Media;
        [FieldOffset(0)] internal readonly MediaPlayerEvents MediaPlayer;
        [FieldOffset(0)] internal readonly MediaListEvents MediaList;
        [FieldOffset(0)] internal readonly MediaListPlayerEvents MediaListPlayer;
        [FieldOffset(0)] internal readonly VlmMediaEvent Vlm;
        [StructLayout(LayoutKind.Explicit)]
        internal readonly struct MediaEvents
        {
            [FieldOffset(0)] internal readonly MediaMetaChanged MetaChanged;
            [FieldOffset(0)] internal readonly MediaSubItemAdded SubItemAdded;
            [FieldOffset(0)] internal readonly MediaDurationChanged DurationChanged;
            [FieldOffset(0)] internal readonly MediaParsedChanged ParsedChanged;
            [FieldOffset(0)] internal readonly MediaFreed Freed;
            [FieldOffset(0)] internal readonly MediaStateChanged StateChanged;
            [FieldOffset(0)] internal readonly MediaSubItemTreeAdded SubItemTreeAdded;
        }
        [StructLayout(LayoutKind.Explicit)]
        internal readonly struct MediaPlayerEvents
        {
            [FieldOffset(0)] internal readonly MediaPlayerBuffering Buffering;
            [FieldOffset(0)] internal readonly MediaPlayerPositionChanged PositionChanged;
            [FieldOffset(0)] internal readonly MediaPlayerTimeChanged TimeChanged;
            [FieldOffset(0)] internal readonly MediaPlayerTitleChanged TitleChanged;
            [FieldOffset(0)] internal readonly MediaPlayerSeekableChanged SeekableChanged;
            [FieldOffset(0)] internal readonly MediaPlayerPausableChanged PausableChanged;
            [FieldOffset(0)] internal readonly MediaPlayerScrambledChanged ScrambledChanged;
            [FieldOffset(0)] internal readonly MediaPlayerVideoOutput VideoOutput;
            [FieldOffset(0)] internal readonly MediaPlayerLengthChanged LengthChanged;
            [FieldOffset(0)] internal readonly MediaPlayerSnapshotTaken SnapshotTaken;
            [FieldOffset(0)] internal readonly MediaPlayerMediaChanged MediaChanged;
            [FieldOffset(0)] internal readonly MediaPlayerAudioVolume AudioVolume;
        }
        [StructLayout(LayoutKind.Explicit)]
        internal readonly struct MediaListPlayerEvents
        {
            [FieldOffset(0)] internal readonly MediaListPlayerNextItemSet NextItemSet;
        }
        [StructLayout(LayoutKind.Explicit)]
        internal readonly struct MediaListEvents
        {
            [FieldOffset(0)] internal readonly MediaListItemAdded ItemAdded;
            [FieldOffset(0)] internal readonly MediaListWilAddItem WillAddItem;
            [FieldOffset(0)] internal readonly MediaListItemDeleted ItemDeleted;
            [FieldOffset(0)] internal readonly MediaListWillDeleteItem WillDeleteItem;
        }
    }
    #region Media
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaMetaChanged
    {
        internal readonly MetaType MetaType;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaSubItemAdded
    {
        internal readonly IntPtr NewChild;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaDurationChanged
    {
        internal readonly long NewDuration;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaParsedChanged
    {
        internal readonly int NewStatus;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaFreed
    {
        internal readonly IntPtr MediaPtr;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaStateChanged
    {
        internal readonly State NewState;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaSubItemTreeAdded
    {
        internal readonly IntPtr NewItem;
    }
    #endregion
    #region MediaPlayer
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerBuffering
    {
        internal readonly float NewCache;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerPositionChanged
    {
        internal readonly float NewPosition;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerTimeChanged
    {
        internal readonly long NewTime;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerTitleChanged
    {
        internal readonly int NewTitle;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerSeekableChanged
    {
        internal readonly int NewSeekable;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerPausableChanged
    {
        internal readonly int NewPausable;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerScrambledChanged
    {
        internal readonly int NewScrambled;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerVideoOutput
    {
        internal readonly int NewCount;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerLengthChanged
    {
        internal readonly long NewLength;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerSnapshotTaken
    {
        internal readonly IntPtr FileName;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerMediaChanged
    {
        internal readonly IntPtr NewMedia;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaPlayerAudioVolume
    {
        internal readonly float Volume;
    }
    #endregion
    #region Media List
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaListItemAdded
    {
        internal readonly IntPtr Item;
        internal readonly int Index;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaListWilAddItem
    {
        internal readonly IntPtr Item;
        internal readonly int Index;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaListItemDeleted
    {
        internal readonly IntPtr Item;
        internal readonly int Index;
    }
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaListWillDeleteItem
    {
        internal readonly IntPtr Item;
        internal readonly int Index;
    }
    #endregion
    #region Media List Player
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct MediaListPlayerNextItemSet
    {
        internal readonly IntPtr Item;
    }
    #endregion
    #region Vlm
    [StructLayout(LayoutKind.Sequential)]
    internal readonly struct VlmMediaEvent
    {
        internal readonly IntPtr MediaName;
        internal readonly IntPtr InstanceName;
    }
    #endregion
}
READ ALSO
Entity FrameWork и наследование

Entity FrameWork и наследование

Прошу разрешить диллему, суть которой такова: Есть БД с сущностями представляющими факультет (студент, преподаватель, оценки, кафедры, и тд

270
Order by many to many relation in laravel

Order by many to many relation in laravel

Имеем отношение Many to Many

196
Замена хэштегов на ссылки

Замена хэштегов на ссылки

Пытаюсь реализовать хэштегиЗаменить каждый хэштег на ссылку

80
Как замокать метод с обращением в БД

Как замокать метод с обращением в БД

Есть класс с двумя методами, один оперирует данными взятыми из второгоНужно протестировать метод sum не получая данных из метода db, а подставив...

199