Skip to content
Discussion options

You must be logged in to vote

NO1. how to cteate a Span property from a fixed size buffer ?
You could write:

using System;

struct Foo
{
    private const int BufLen = 128;
    private unsafe fixed byte Buffer[BufLen];
    public Span<byte> Data {
         get{
             unsafe {
                 fixed(Byte* ptr = &Buffer[0]){
                     return new Span<byte>(ptr, BufLen);
                 }    
             }
         }
    }
}

NO2.how to use sizeof like C++ in C# get the size of fixed size buffer ?
There is no sizeof support. The type of an fixed buffer access is just a pointer.

NO3.how to create a Extension Method for fixed size buffer?
You can't create extension method for pointers -> you can't create…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@yaakov-h
Comment options

@sgf
Comment options

@jnm2
Comment options

jnm2 Sep 13, 2021
Collaborator

Answer selected by sgf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants