Opened 4 years ago
Closed 4 years ago
#16638 closed bug (fixed)
ObjectDeleter: size in twice bigger then regular pointer
Reported by: | X512 | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | - General | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
This is hrev54752.
AutoDeleter use DeleteFunc fDelete
field. C++ don't like zero field size and adjust it to 1 byte. After alignment ObjectDeleter size become 2*sizeof(void*)
. See test code.
There are no such problem in std::unique_ptr
. It use some C++ tricks that need to be investigated and reused in AutoDeleter.h
.
Attachments (1)
Change History (6)
by , 4 years ago
Attachment: | PtrSize.cpp added |
---|
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Following trick can fix issue:
-
headers/private/shared/AutoDeleter.h
diff --git a/headers/private/shared/AutoDeleter.h b/headers/private/shared/AutoDeleter.h index 7f16091809..b77f007185 100644
a b template<typename C, typename DeleteFunc> 29 29 class AutoDeleter { 30 30 public: 31 31 inline AutoDeleter() 32 : f Object(NULL)32 : fInt(NULL) 33 33 { 34 34 } 35 35 36 36 inline AutoDeleter(C *object) 37 : f Object(object)37 : fInt(object) 38 38 { 39 39 } 40 40 41 41 inline ~AutoDeleter() 42 42 { 43 f Delete(fObject);43 fInt(fInt.fObject); 44 44 } 45 45 46 46 inline void SetTo(C *object) 47 47 { 48 if (object != f Object) {49 f Delete(fObject);50 f Object = object;48 if (object != fInt.fObject) { 49 fInt(fInt.fObject); 50 fInt.fObject = object; 51 51 } 52 52 } 53 53 … … public: 63 63 64 64 inline C *Get() const 65 65 { 66 return f Object;66 return fInt.fObject; 67 67 } 68 68 69 69 inline C *Detach() 70 70 { 71 C *object = f Object;72 f Object = NULL;71 C *object = fInt.fObject; 72 fInt.fObject = NULL; 73 73 return object; 74 74 } 75 75 76 76 inline C *operator->() const 77 77 { 78 return f Object;78 return fInt.fObject; 79 79 } 80 80 81 81 protected: 82 C *fObject; 83 DeleteFunc fDelete; 82 struct Internal: DeleteFunc { 83 C* fObject; 84 inline Internal(C *object): fObject(object) {} 85 } fInt; 84 86 85 87 private: 86 88 AutoDeleter(const AutoDeleter&);
comment:3 by , 4 years ago
Similar problem with CObjectDeleter
, but it actually store pointer to destructor function. I suggest interface change from CObjectDeleter<Type, DestructorResult> ptr(val, destructor)
to CObjectDeleter<Type, DestructorResult, destructor> ptr(val)
. It will also allow to declare typedef
for specific pointer type with destructor function.
comment:5 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Test program output: