File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -340,12 +340,17 @@ void* TWithExtraSpace<T>::GetExtraSpacePtr()
340
340
}
341
341
342
342
template <class T >
343
- size_t TWithExtraSpace<T>::GetUsableSpaceSize() const
343
+ std::optional< size_t > TWithExtraSpace<T>::GetUsableSpaceSize() const
344
344
{
345
345
#ifdef _win_
346
346
return 0 ;
347
347
#else
348
- return malloc_usable_size (const_cast <T*>(static_cast <const T*>(this ))) - sizeof (T);
348
+ size_t usableSize = malloc_usable_size (const_cast <T*>(static_cast <const T*>(this )));
349
+ if (usableSize == 0 ) {
350
+ return std::nullopt;
351
+ }
352
+ YT_ASSERT (usableSize >= sizeof (T));
353
+ return usableSize - sizeof (T);
349
354
#endif
350
355
}
351
356
Original file line number Diff line number Diff line change @@ -130,9 +130,14 @@ template <class T>
130
130
class TWithExtraSpace
131
131
{
132
132
protected:
133
+ // ! Returns the pointer to the extra space associated with this instance.
133
134
const void * GetExtraSpacePtr () const ;
134
135
void * GetExtraSpacePtr ();
135
- size_t GetUsableSpaceSize () const ;
136
+
137
+ // ! Returns the size of the extra space associated with this instance.
138
+ // ! This is determined via the call to |malloc_usable_size| and may be
139
+ // ! null if the allocator support is unavailable.
140
+ std::optional<size_t > GetUsableSpaceSize () const ;
136
141
};
137
142
138
143
// //////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change @@ -150,8 +150,8 @@ class TDefaultAllocationHolder
150
150
TRefCountedTypeCookie cookie)
151
151
{
152
152
if (options.ExtendToUsableSize ) {
153
- if (auto usableSize = GetUsableSpaceSize (); usableSize != 0 ) {
154
- size = usableSize;
153
+ if (auto usableSize = GetUsableSpaceSize ()) {
154
+ size = * usableSize;
155
155
}
156
156
}
157
157
Initialize (size, options, cookie);
You can’t perform that action at this time.
0 commit comments