@@ -72,19 +72,20 @@ class FBOW_API Vocabulary
7272 }
7373
7474 static inline void AlignedFree (void *ptr){
75+ if (ptr==nullptr )return ;
7576 unsigned char *uptr=(unsigned char *)ptr;
7677 unsigned char off= *(uptr-1 );
7778 uptr-=off;
7879 std::free (uptr);
7980 }
8081
81- using Data_ptr = std::unique_ptr<char [], decltype (&AlignedFree)>;
82+ // using Data_ptr = std::unique_ptr<char[], decltype(&AlignedFree)>;
8283
8384 friend class VocabularyCreator ;
8485
8586 public:
8687
87- Vocabulary () = default ;
88+ Vocabulary (): _data(( char *) nullptr ,&AlignedFree){}
8889 Vocabulary (Vocabulary&&) = default ;
8990
9091 // transform the features stored as rows in the returned BagOfWords
@@ -107,7 +108,7 @@ class FBOW_API Vocabulary
107108 // returns the branching factor (number of children per node)
108109 uint32_t getK ()const {return _params._m_k ;}
109110 // indicates whether this object is valid
110- bool isValid ()const {return _data!= 0 ;}
111+ bool isValid ()const {return _data. get ()!= nullptr ;}
111112 // total number of blocks
112113 size_t size ()const {return _params._nblocks ;}
113114 // removes all data
@@ -129,7 +130,8 @@ class FBOW_API Vocabulary
129130 uint32_t _m_k=0 ;// number of children per node
130131 };
131132 params _params;
132- Data_ptr _data = Data_ptr(nullptr , &AlignedFree);// pointer to data
133+ std::unique_ptr<char [], decltype (&AlignedFree)> _data;
134+
133135
134136 // structure represeting a information about node in a block
135137 struct block_node_info {
@@ -194,7 +196,7 @@ class FBOW_API Vocabulary
194196
195197
196198 // returns a block structure pointing at block b
197- inline Block getBlock (uint32_t b) { assert (_data != 0 ); assert (b < _params._nblocks ); return Block (_data.get () + b * _params._block_size_bytes_wp , _params._desc_size , _params._desc_size_bytes_wp , _params._feature_off_start , _params._child_off_start ); }
199+ inline Block getBlock (uint32_t b) { assert (_data. get () != nullptr ); assert (b < _params._nblocks ); return Block (_data.get () + b * _params._block_size_bytes_wp , _params._desc_size , _params._desc_size_bytes_wp , _params._feature_off_start , _params._child_off_start ); }
198200 // given a block already create with getBlock, moves it to point to block b
199201 inline void setBlock (uint32_t b, Block &block) { block._blockstart = _data.get () + b * _params._block_size_bytes_wp ; }
200202
0 commit comments