mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
`NSData`/`NSMutableData` provide constructors which internally mark them for auto-release pool. New obj-c rule of thumb: If an object is created and auto-released, releasing them manually still keeps them in the pool, and the pool will still try to release the object despite being released already, and end up causing a segmentation fault error. Any object created with a convenient constructor is marked as auto-released (see https://stackoverflow.com/a/24807570), and therefore methods to manually release them should NOT be exposed.
30 lines
996 B
C#
30 lines
996 B
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
using System;
|
|
|
|
namespace osu.Framework.Platform.Apple.Native
|
|
{
|
|
internal readonly struct NSMutableData
|
|
{
|
|
internal IntPtr Handle { get; }
|
|
|
|
private static readonly IntPtr class_pointer = Class.Get("NSMutableData");
|
|
private static readonly IntPtr sel_data_with_length = Selector.Get("dataWithLength:");
|
|
private static readonly IntPtr sel_mutable_bytes = Selector.Get("mutableBytes");
|
|
|
|
internal NSMutableData(IntPtr handle)
|
|
{
|
|
Handle = handle;
|
|
}
|
|
|
|
internal unsafe byte* MutableBytes => (byte*)Interop.SendIntPtr(Handle, sel_mutable_bytes);
|
|
|
|
internal static NSMutableData FromLength(int length)
|
|
{
|
|
IntPtr handle = Interop.SendIntPtr(class_pointer, sel_data_with_length, length);
|
|
return new NSMutableData(handle);
|
|
}
|
|
}
|
|
}
|