Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get fixed buffer length?

Is there a way to get the length of a fixed size buffer?

Something like:

public struct MyStruct
{
    public unsafe fixed byte buffer[100];

    public int foo()
    {
        return sizeof(buffer); // Compile error.
    }
}

Is there any way to accomplish something like this?

like image 580
andresantacruz Avatar asked May 09 '16 17:05

andresantacruz


People also ask

What is a fixed length buffer?

A fixed size buffer is a member that represents storage for a fixed length buffer of variables of a given type. A fixed size buffer declaration introduces one or more fixed size buffers of a given element type. Fixed size buffers are only permitted in struct declarations and can only occur in unsafe contexts.

What is a fixed buffer?

Fixed buffer stops are essentially 'end of line' systems with frames fixed directly onto the rails, these type of buffer stops have no energy absorbing ability unless used in conjunction with Oleo hydraulic energy absorption systems to dissipate the impact energy.

What is buffer and buffer size?

What is buffer size? Buffer size is the number of samples (which corresponds to the amount of time) it takes for your computer to process any incoming audio signal. A higher buffer size will result in greater latency (delay) and the higher it is set (larger number), the more noticeable it will become.


1 Answers

Well like in C++, you have to keep size of built-in arrays. Same applies for fixed buffers in C#. This type is comparable to inline_array. This gives you benefits such as static code checking. They are a bit of a pain to work with as they aren't C#'s first class feature. So probably the best solution is to keep size as a part of struct. You will probably just have to deal with it or use a collection/C#'s System.Array. Maybe another solution would be to create fixed buffer as a seperate struct and then make it part of another stucts with other data.

like image 194
fsacer Avatar answered Oct 20 '22 00:10

fsacer