开发者

How do I specify a fixed-size buffer in C++/CLI?

开发者 https://www.devze.com 2022-12-17 08:47 出处:网络
In C#, I c开发者_开发知识库an specify a fixed sized buffer using the fixed keyword, like so: public unsafe struct StructWithFixedBuffer

In C#, I c开发者_开发知识库an specify a fixed sized buffer using the fixed keyword, like so:

public unsafe struct StructWithFixedBuffer
{
    public fixed char FixedBuffer[128];
}

how would I express the same thing in C++/CLI?


One of the C++/CLI developer blogs had code for a template solution to this, I'll try to find a link.

Ahh, found it. It's called inline_array.


The C# syntax was added as a way to express the C++ syntax you've know forever. :)

public:
    wchar_t FixedBuffer[128];


Quote:

size of the 128 element char array is 256 bytes. Fixed size char buffers always take two bytes per character, regardless of the encoding.

So you want:

struct StructWithFixedBuffer
{
    char FixedBuffer[128*2];
};
0

精彩评论

暂无评论...
验证码 换一张
取 消