使用malloc/free()实现的Vulkan的VkAllocationCallbacks [英] Vulkan's VkAllocationCallbacks implemented with malloc/free()

查看:180
本文介绍了使用malloc/free()实现的Vulkan的VkAllocationCallbacks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 Vulkan内存分配-内存主机,似乎可以使用朴素的malloc/realloc/free函数来实现VkAllocationCallbacks.

I'm reading Vulkan Memory Allocation - Memory Host and seems that VkAllocationCallbacks can be implemented using naive malloc/realloc/free functions.

typedef struct VkAllocationCallbacks {
   void*                                   pUserData;
   PFN_vkAllocationFunction                pfnAllocation;
   PFN_vkReallocationFunction              pfnReallocation;
   PFN_vkFreeFunction                      pfnFree;
   PFN_vkInternalAllocationNotification    pfnInternalAllocation;
   PFN_vkInternalFreeNotification          pfnInternalFree;
} VkAllocationCallbacks;

但是我仅看到两个可能的原因来实现自己的vkAllocationCallback:

But I see only two possible reasons to implement my own vkAllocationCallback:

  • 通过Vulkan API记录和跟踪内存使用情况;
  • 实现一种堆内存管理,它是一遍又一遍地要使用和重用的大块内存.显然,这可能是一个过大的选择,并且会遭受与托管内存相同的问题(与Java JVM中一样).

我在这里想念什么吗? 什么样的应用程序值得实现vkAllocationCallbacks?

Am I missing something here ? What sort of applications would worth implementing vkAllocationCallbacks ?

推荐答案

根据规范:由于大多数内存分配不在关键路径上,因此这并不意味着其性能.相反,这对于某些嵌入式系统可能很有用.系统,用于调试目的(例如,在所有主机分配之后放置保护页),或用于内存分配日志记录."

From the spec: "Since most memory allocations are off the critical path, this is not meant as a performance feature. Rather, this can be useful for certain embedded systems, for debugging purposes (e.g. putting a guard page after all host allocations), or for memory allocation logging."

在嵌入式系统中,您可能一开始就抓住了所有内存,所以您不希望驱动程序调用malloc,因为储罐中可能没有任何东西.保护页和内存日志记录(仅用于调试版本)对于谨慎/好奇的人可能很有用.

With an embedded system, you might have grabbed all the memory right at the start, so you don't want the driver calling malloc because there might be nothing left in the tank. Guard pages and memory logging (for debug builds only) could be useful for the cautious/curious.

我在某处的幻灯片上读到了(不记得在哪儿,对不起),您绝对不应该实现仅传递给malloc/realloc/free的分配回调,因为您通常可以假设驱动程序做得更好除此之外(例如将少量分配合并到池中).

I read on a slide somewhere (can't remember where, sorry) that you definitely should not implement allocation callbacks that just feed through to malloc/realloc/free because you can generally assume that the drivers are doing a much better job than that (e.g. consolidating small allocations into pools).

我认为,如果您不确定是否应该实现分配回调,那么就不需要实现分配回调,也不必担心也许应该这样做.

I think that if you're not sure whether you ought to be implementing allocation callbacks, then you don't need to implement allocation callbacks and you don't need to worry that maybe you should have.

我认为它们适合那些特定的用例和真正想要控制一切的人.

I think they're there for those specific use cases and for those who really want to be in control of everything.

这篇关于使用malloc/free()实现的Vulkan的VkAllocationCallbacks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆