From 0acdbebf3b47f6f47f5bea69c2fa62d57637d708 Mon Sep 17 00:00:00 2001 From: nihui Date: Sat, 16 Feb 2019 14:53:50 +0800 Subject: [PATCH] merge refcount into buffer memory cookie --- src/allocator.h | 2 ++ src/mat.h | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/allocator.h b/src/allocator.h index 71b38821c..1f2427068 100644 --- a/src/allocator.h +++ b/src/allocator.h @@ -199,6 +199,8 @@ public: size_t capacity; VkDeviceMemory memory; void* mapped_ptr; + // initialize and modified by mat + int refcount; }; class VkAllocator diff --git a/src/mat.h b/src/mat.h index 98b989099..dda78ff67 100644 --- a/src/mat.h +++ b/src/mat.h @@ -1217,7 +1217,7 @@ inline void VkMat::create(int _w, size_t _elemsize, VkAllocator* _allocator, VkA state = 1; - refcount = new int; + refcount = (int*)((unsigned char*)data + offsetof(VkBufferMemory, refcount)); *refcount = 1; } } @@ -1250,7 +1250,7 @@ inline void VkMat::create(int _w, int _h, size_t _elemsize, VkAllocator* _alloca state = 1; - refcount = new int; + refcount = (int*)((unsigned char*)data + offsetof(VkBufferMemory, refcount)); *refcount = 1; } } @@ -1283,7 +1283,7 @@ inline void VkMat::create(int _w, int _h, int _c, size_t _elemsize, VkAllocator* state = 1; - refcount = new int; + refcount = (int*)((unsigned char*)data + offsetof(VkBufferMemory, refcount)); *refcount = 1; } } @@ -1316,7 +1316,7 @@ inline void VkMat::create(int _w, size_t _elemsize, int _packing, VkAllocator* _ state = 1; - refcount = new int; + refcount = (int*)((unsigned char*)data + offsetof(VkBufferMemory, refcount)); *refcount = 1; } } @@ -1349,7 +1349,7 @@ inline void VkMat::create(int _w, int _h, size_t _elemsize, int _packing, VkAllo state = 1; - refcount = new int; + refcount = (int*)((unsigned char*)data + offsetof(VkBufferMemory, refcount)); *refcount = 1; } } @@ -1382,7 +1382,7 @@ inline void VkMat::create(int _w, int _h, int _c, size_t _elemsize, int _packing state = 1; - refcount = new int; + refcount = (int*)((unsigned char*)data + offsetof(VkBufferMemory, refcount)); *refcount = 1; } } @@ -1478,8 +1478,6 @@ inline void VkMat::release() { staging_allocator->fastFree(staging_data); } - - delete refcount; } data = 0;