[ https://issues.apache.org/jira/browse/GEODE-8756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17251944#comment-17251944 ]
ASF subversion and git services commented on GEODE-8756: -------------------------------------------------------- Commit 4f504e4c4b229d883002d6dfb0a5512277ebfb69 in geode-native's branch refs/heads/develop from Mario Salazar de Torres [ https://gitbox.apache.org/repos/asf?p=geode-native.git;h=4f504e4 ] GEODE-8756: Fix CacheableString::objectSize (#703) - objectSize was not taking into account null-terminator character, which as of C++11, as stated in § 21.4.7.1, should be included at the end of the same string character sequence. - Also, in those cases in which SSO applied, the returned size was higher than the actual one. - A parametrized UT was added to check objectSize is returning the right size. Note that no fixed sizes are part of such test, given that each std::string implementation could have a different SSO size. * Revision 2 - Added a new class called size_tracking_allocator, which is a custom allocator used to track the size STL objects. - Changed testing approach so it does not replicate internal logic, and instead it instantiates a basic_string<char> with the new custom allocator so heap size is tracked this way. > CacheableString objectSize is not correct > ----------------------------------------- > > Key: GEODE-8756 > URL: https://issues.apache.org/jira/browse/GEODE-8756 > Project: Geode > Issue Type: Sub-task > Components: native client > Affects Versions: 1.11.0, 1.12.0, 1.13.0, 1.13.1 > Reporter: Mario Salazar de Torres > Assignee: Mario Salazar de Torres > Priority: Major > Labels: pull-request-available > > CacheableString objectSize function is returning an incorrect value. > This class is based upon STL's string implementation, and most of the > compilers implementations apply what's called SSO. > What SSO basically does is if the string occupies less than a certain amount, > no extra memory would be allocated in the heap, and the character-sequence > would be stored in the object itself. This is typically achieved by using > union semantics. > Right now if SSO applies, objectSize calculates the size of std::string as > sizeof(std::string) + m_str.capacity(), which is more than it actually > occupies. > On the other hand starting C++11 STL's strings needs to allocate an extra > character > to keep the null-terminator in the same buffer as the actual string. This is > specified in section § 21.4.7.1 within the C++11 standard. > Because of this objectSize should take the null-terminator into account, > which was not the case. -- This message was sent by Atlassian Jira (v8.3.4#803005)