You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most C++ implementations of std::string will allocate a new block when appending a string (unless the implementation is specifically tuned to always allocate extra space after a string assignment); and then the data from the old block is copied to the new block, and the old block is freed. The memory pool implementation doesn't have to allocate a new block. It just extends the current block and so it gains the speed advantage.
It would be a fairer benchmark if the String class were templated and it took an Allocator where the allocator could either be the standard C++ allocator, or the MemoryPool allocator. That way it can be shown that the same operations are being performed, but MemoryPool is actually faster.
The text was updated successfully, but these errors were encountered:
Interesting Idea.
I think I will just create another implementation of String which uses the regular new & delete and compare it to the implementation with the current string class, what do you say?
You can't mix in calling the standard C realloc() to reallocate a memory block that has been allocated using new. Yes, it may work with some C/C++ runtime implementations, but there is no guarantee that it always will, specially if the user override the global new with their own implementation.
Most C++ implementations of
std::string
will allocate a new block when appending a string (unless the implementation is specifically tuned to always allocate extra space after a string assignment); and then the data from the old block is copied to the new block, and the old block is freed. The memory pool implementation doesn't have to allocate a new block. It just extends the current block and so it gains the speed advantage.It would be a fairer benchmark if the
String
class were templated and it took anAllocator
where the allocator could either be the standard C++ allocator, or the MemoryPool allocator. That way it can be shown that the same operations are being performed, but MemoryPool is actually faster.The text was updated successfully, but these errors were encountered: