简体   繁体   English

如何在 C# 中调用

[英]How to calloc in C#

public unsafe struct AVContext
{
   public AVFormatContext* AVFC;
   public AVCodec* videoCodec;
}
    
AVContext *decoder = (AVContext*) calloc(1, sizeof(AVContext));
      

How can i initiate a new struct like this in c#?我如何在 c# 中启动这样的新结构? Is there a calloc function in c#? c#中是否有calloc function? Thanks in advance!提前致谢!

Yes, though it's not what you want.是的,虽然这不是你想要的。 You have NativeMemory.AllocZeroed for newer.Net versions, and Marshal.AllocHGlobal for older ones.对于较新的.Net 版本,您有NativeMemory.AllocZeroed ,对于较旧的版本,您有Marshal.AllocHGlobal

But again, not what you want.但同样,不是你想要的。 Ffmpeg does its own allocating with its own methods. Ffmpeg 使用自己的方法进行自己的分配。 It also has its own memory free functions.它还具有自己的 memory 免费功能。 Here's a quick example of how to initialize the format context, for example:下面是一个如何初始化格式上下文的快速示例,例如:

fixed (AVFormatContext** pFormatContext = &formatContext)
    CheckAvSuccess(ffmpeg.avformat_open_input(pFormatContext, path, null, null));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM