Vulkan Cookbook 第一章 21 释放Vulkan Loader库

本文详细介绍了如何在Windows和Linux操作系统上正确释放VulkanLoader库,确保应用程序资源得到妥善管理。在Windows上使用FreeLibrary()函数,在Linux上使用dlclose()函数,并将句柄变量设置为nullptr,以避免内存泄漏。

释放Vulkan Loader库

译者注:示例代码点击此处

必须显式关闭(释放)动态加载的库。 为了能够在我们的应用程序中使用Vulkan,我们打开了Vulkan Loader(Windows上的vulkan-1.dll库或Linux上的libvulkan.so.1库)。 因此,在我们关闭应用程序之前,我们应该释放它。

怎么做...

在Windows操作系统上:
    1.获取名为vulkan_libraryHMODULE类型的变量,其中存储了已加载的Vulkan Loader的句柄(请参阅连接Vulkan Loader库)。
    2.调用FreeLibrary(vulkan_library)并将vulkan_library传给它。
    3.出于安全原因,将nullptr值分配给vulkan_library变量。

在Liunx操作系统上
     1.获取名为vulkan_libraryvoid*类型的变量,其中存储了已加载的Vulkan Loader的句柄(请参阅连接Vulkan Loader库)。
    2.调用closed(vulkan_library)并将vulkan_library传给它。
    3.出于安全原因,将nullptr值分配给vulkan_library变量。

这个怎么运作...

在Windows操作系统系列中,使用LoadLibrary()函数打开动态库。 必须通过提供以先前打开的库的句柄调用的FreeLibrary()函数来关闭(释放)这些库。
在Linux操作系统系列中,使用dlopen()函数打开动态库。 必须通过提供以先前打开的库的句柄调用的dlclose()函数来关闭(释放)此类库:

#if defined _WIN32 
FreeLibrary( vulkan_library ); 
#elif defined __linux 
dlclose( vulkan_library ); 
#endif
vulkan_library = nullptr;

 

Computer graphics have a very long and interesting history. Many APIs or custom approaches to the generation of 2D or 3D images have come and gone. A landmark in this history was the invention of OpenGL, one of the first graphics libraries, which allowed us to create real-time, high-performance 3D graphics, and which was available for everyone on multiple operating systems. It is still developed and widely used even today. And this year we can celebrate its 25th birthday! But many things have changed since OpenGL was created. The graphics hardware industry is evolving very quickly. And recently, to accommodate these changes, a new approach to 3D graphics rendering was presented. It took the form of a low-level access to the graphics hardware. OpenGL was designed as a high-level API, which allows users to easily render images on screen. But this high-level approach, convenient for users, is difficult for graphics drivers to handle. This is one of the main reasons for restricting the hardware to show its full potential. The new approach tries to overcome these struggles–it gives users much more control over the hardware, but also many more responsibilities. This way application developers can release the full potential of the graphics hardware, because the drivers no longer block them. Low-level access allows drivers to be much smaller, much thinner. But these benefits come at the expense of much more work that needs to done by the developers. The first evangelist of the new approach to graphics rendering was a Mantle API designed by AMD. When it proved that low-level access can give considerable performance benefits, other companies started working on their own graphics libraries. One of the most notable representatives of the new trend were Metal API, designed by Apple, and DirectX 12, developed by Microsoft. But all of the above libraries were developed with specific operating systems and/or hardware in mind. There was no open and multiplatform standard such as OpenGL. Until last year. Year 2016 saw the release of the Vulkan API, developed by Khronos consortium, which maintains the OpenGL library. Vulkan also represents the new approach, a low-level access to the graphics hardware, but unlike the other libraries it is available for everyone on multiple operating systems and hardware platforms–from high-performance desktop computers with Windows or Linux operating systems, to mobile devices with Android OS. And as it is still being very new, there are few resources teaching developers how to use it. This book tries to fill this gap.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值